Share via


CreateStrokes Method

CreateStrokes Method

Creates a new InkStrokes collection from existing IInkStrokeDisp objects.

Declaration

[C++]

HRESULT CreateStrokes (
    [in, optional, defaultvalue(0)] VARIANT ids,
    [out, retval] IInkStrokes** strokes
);

[Microsoft® Visual Basic® 6.0]

Public Function CreateStrokes( _
    [Optional ids() as Long = Nothing] _
) As InkStrokes

Parameters

ids

[in, optional] Specifies an array of stroke IDs that exist in the InkDisp object. The strokes with these IDs are added to a new InkStrokes collection. The default value is NULL (Nothing in Visual Basic 6.0).

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

strokes

[out, retval] Returns a new InkStrokes collection.

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 Strokes collection.
TPC_E_INVALID_STROKE Stroke IDs that do not exist were passed to the method.

Remarks

If the ids parameter is NULL or an empty array, then an empty InkStrokes collection is created.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example uses a command button, Command1, to invoke a function, DeleteStrokesOnLeft, that deletes all of the strokes in the InkDisp object, theInkCollector.Ink, that are to the left of the ptLeft parameter, and returns a count of the deleted strokes.

        Dim theInkCollector As InkCollector

Private Sub Command1_Click()
    ' On button press, delete all strokes with points
    ' to the left of a line at x=5000 in ink space
    DeleteStrokesOnLeft 5000
    Form1.Refresh
End Sub

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

Public Function DeleteStrokesOnLeft( _
    ByVal ptLeft As Long _
) As Long
    Dim i As Integer
    Dim ptTest As Long
    Dim stroke As IInkStrokeDisp
    Dim strokesToDelete As InkStrokes
    Dim ptStrokePoints As Variant

    ' Create an object to hold strokes to be deleted
    Set strokesToDelete = theInkCollector.Ink.CreateStrokes

    For Each stroke In theInkCollector.Ink.Strokes
        ' The points are returned as an array of Long,
        ' in the form of x1, y1, x2, y2, ...
        ptStrokePoints = stroke.GetPoints
        ' Determine the final x,y pair starting at 0
        Dim pointUBound As Long
        pointUBound = (UBound(ptStrokePoints) - 1) \ 2
        For i = 0 To pointUBound
            ' Get the next point x value
            ptTest = ptStrokePoints(i * 2)
            ' If there is a point in this stroke left of the parameter,
            If ptTest < ptLeft Then
                ' add this stroke to the collection to delete
                strokesToDelete.Add stroke
                ' then exit, because we don't need to test further.
                Exit For
            End If
        Next
    Next
    If 0 < strokesToDelete.Count Then
        ' Delete the strokes we collected on the left
        theInkCollector.Ink.DeleteStrokes strokesToDelete
    End If
    DeleteStrokesOnLeft = strokesToDelete.Count
End Function
      

Applies To