DeleteStrokes Method

DeleteStrokes Method

Deletes a InkStrokes collection from the Strokes collection of the InkDisp object.

Declaration

[C++]

HRESULT DeleteStrokes (
    [in, optional, defaultvalue(0)] IInkStrokes* strokes
);

[Microsoft® Visual Basic® 6.0]

Public Sub DeleteStrokes([strokes As InkStrokes])

Parameters

strokes

[in] Specifies the collection of strokes to delete from the InkDisp object. The default value is NULL (Nothing in Visual Basic 6.0, which must be specified if using latebinding).

Return Value

HRESULT value Description
S_OK Success.
E_POINTER A parameter contained an invalid pointer.
E_OUTOFMEMORY Cannot allocate memory that is used to perform the operation.
E_FAIL An unspecified error occurred.
E_INK_MISMATCHED_INK_OBJECT The InkDisp object of the strokes must match the known InkDisp object.
E_INK_EXCEPTION An exception occurred inside the method.
E_UNEXPECTED Unexpected parameter or property type.

Remarks

This method deletes all of the strokes in the InkDisp object if no InkStrokes collection is passed in. To delete only one stroke at a time, call the DeleteStroke method.

The InkDisp object renumbers the indices of the remaining strokes in the InkDisp object if the strokes that were deleted do not fall at the end of the InkDisp object's collection of strokes.

Note: The contents of a InkStrokes collection become invalid when strokes that are contained in the collection are deleted from the InkDisp object.

DeleteStrokes can result in an error if called while the user is actively laying down ink.

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 in ink space, 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