CreateStroke Method

CreateStroke Method

Creates a IInkStrokeDisp object from an array of packet data input values.

Declaration

[C++]

HRESULT CreateStroke (
    [in] VARIANT packetData,
    [in] VARIANT packetDescription,
    [out, retval] IInkStrokeDisp **Stroke
);

[Microsoft® Visual Basic® 6.0]

Public Function CreateStroke( _
    packetData As Variant, _
    packetDescription As Variant _
) As IInkStrokeDisp

Parameters

packetData

[in] Specifies the array of packet data. The data is an array of Int32 (Long in Visual Basic) values which, taken in order, form the array of points (x0, y0), (x1, y1), which is passed into the method within a Variant.

For more information about the VARIANT structure, see Using the Automation Library.

packetDescription

[in] Is a reserved parameter that is currently not implemented.

Stroke

[out, retval] Returns the newly created stroke.

Return Value

HRESULT value Description
S_OK Success.
E_POINTER A parameter contained an invalid pointer.
E_INVALIDARG Invalid VARIANT type (only VT_ARRAY | VT_I4 supported).
E_INK_EXCEPTION An exception occurred inside the method.
E_OUTOFMEMORY Cannot allocate memory to create the new stroke.

Remarks

The minimum and maximum values of any point in the points array are LONG_MIN and LONG_MAX, respectively. However, these points define an ink space rectangle whose maximum width or height cannot exceed LONG_MAX. Because of this, the difference between the minimum and maximum x-coordinates, or the minimum and maximum y-coordinates, cannot exceed LONG_MAX.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example creates a IInkStrokeDisp, theStroke, in an InkDisp object, theInkCollector.Ink, from array of point data, ptStrokePoints.

Option Explicit
Dim theInkCollector As InkCollector

Private Sub Form_Load()
    Set theInkCollector = New InkCollector
    theInkCollector.hWnd = Me.hWnd
    theInkCollector.Enabled = True

    'Create a set of three points, stored as x1, y1, x2, y2, x3, y3
    'in an array of six Long elements, starting at index 0.
    Dim ptStrokePoints(5) As Long
    ptStrokePoints(0) = 200
    ptStrokePoints(1) = 200
    ptStrokePoints(2) = 400
    ptStrokePoints(3) = 600
    ptStrokePoints(4) = 900
    ptStrokePoints(5) = 300

    'The description value is an unused placeholder.
    Dim theDescription As Variant
    Dim theStroke As IInkStrokeDisp
  Set theStroke = theInkCollector.Ink.CreateStroke(ptStrokePoints, theDescription)
End Sub
      

[C++]

This C++ example creates a IInkStrokeDisp, pInkStrokeDisp, in an InkDisp object, pInk, from an array of point data.

   VARIANT   var, varPK;
   LONG*   plongArray=NULL;
   POINT   ptArray[2]={0};
   long   lSize=0;
   IInkStrokeDisp* pInkStrokeDisp;

   IInkDisp*   pInk;   // the object should be created correctly
                       // elsewhere and assigned here.
   HRESULT   hr=E_FAIL;

   ptArray[0].x = 20;
   ptArray[0].y = 100;
   ptArray[1].x = 30;
   ptArray[1].y = 110;
   lSize = 2;   // two points

   VariantInit( &var );
   VariantInit( &varPK );
   SAFEARRAY* psa = SafeArrayCreateVector( VT_I4, 0, lSize*2 );
   if( psa )
   {
     if( SUCCEEDED( hr = SafeArrayAccessData( psa, (void**)&plongArray) ))
      {
         for( long i = 0; i < lSize; i++ )
         {
            plongArray[2*i] = ptArray[i].x;
            plongArray[2*i+1] = ptArray[i].y;
         }
         hr = SafeArrayUnaccessData( psa );

         if ( SUCCEEDED( hr ) )
         {
            var.vt     = VT_ARRAY | VT_I4;
            var.parray = psa;

           // varPK (packet description) is currently reserved, so it is
           // just empty variant for now.
            pInk->CreateStroke( var, varPK, &pInkStrokeDisp );
         }
      }
   }
   VariantClear( &var );
   VariantClear( &varPK );
      

Applies To