Compartir a través de


GetStrokesFromTextRange Method

GetStrokesFromTextRange Method

Returns the collection that corresponds to the smallest set of recognition segments that contains a specified character range within the alternate.

Declaration

[C++]

HRESULT GetStrokesFromTextRange (
    [in,out] long *selectionStart,
    [in,out] long *selectionLength,
    [out, retval] IInkStrokes **GetStrokesFromTextRange
);

[Microsoft® Visual Basic® 6.0]

Public Function GetStrokesFromTextRange( _
    selectionStart As Long, _
    selectionLength As Long _
) As InkStrokes

Parameters

selectionStart

[in,out] The start of the character range within this alternate. The character at the selectionStart position is included in the range of recognized text. This parameter is adjusted to the beginning of the smallest recognized set of one or more segments that includes the input selection. The selectionStart parameter is a zero-based index into the characters in the recognition alternate's text.

selectionLength

[in,out] The length of the character range within the alternate. This parameter must be greater than 0. This parameter is adjusted to the length of the smallest set of one or more segments that includes the input selection.

GetStrokesFromTextRange

[out, retval] Returns the collection of strokes that corresponds to the known range of recognized text.

Return Value

This method returns the collection of strokes that corresponds to the known range of recognized text.

HRESULT value Description
S_OK Success.
E_POINTER A parameter contained an invalid pointer.
E_INK_EXCEPTION An exception occurred inside the method.
E_FAIL An unspecified error occurred.
E_OUTOFMEMORY Cannot allocate stroke handler helper object.

Remarks

To further clarify GetStrokesFromTextRange, consider a collection of strokes that has been recognized and for which the best alternate for those strokes is "how are you". The parameter passed to the method is some range within (or possibly all of) this string result. This alternate contains five segments, one for each word and one for each space. The strokes returned correspond to the smallest set of segments that include all of the input range. If the selectionStart parameter is 0, and the selectionLength parameter is 5, creating a range corresponding to the "how a" of the result string, then the strokes returned are all of the recognized strokes that make up the segments "how are". This is the smallest set of segments that includes the input range.

In both word and character based recognizers, spaces are counted as a character. If the input selection corresponds to a space character, then this method returns and empty InkStrokes collection.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example shows how to find the InkStrokes collection that is associated with the smallest set of IInkRecognitionAlternate objects that include the strokes selected by selecting a range of text in a text box containing the results of recognizing the ink strokes. This example starts with a standard .exe application, adds a reference to the Microsoft Tablet PC Type Library, and has a text box Text1 added to the form. Ink is collected and recognized with the top alternate placed in the text box. When a selection is made in the text box with the mouse, the program finds the containing collection of strokes with GetStrokesFromTextRange and colors it red.

Option Explicit
Dim WithEvents theInkCollector As InkCollector
Dim WithEvents theRecognizerContext As InkRecognizerContext
Dim theRecognitionResult As IInkRecognitionResult
Dim hasRecoResult As Boolean
Dim theStrokes As InkStrokes

Private Sub Form_Load()
    ScaleMode = vbPixels
    'Initialize the InkCollector
    Set theInkCollector = New InkCollector
    theInkCollector.hWnd = Me.hWnd
    theInkCollector.Enabled = True
    'Create new RecognizerContext
    Dim theRecognizers As New InkRecognizers
    Dim theRecognizer As IInkRecognizer
    Set theRecognizer = theRecognizers.GetDefaultRecognizer
    Set theRecognizerContext = theRecognizer.CreateRecognizerContext
    'Initialize the recognizer's strokes
    'and assign them to the RecognizerContext
    Set theStrokes = theInkCollector.Ink.Strokes
    Set theRecognizerContext.Strokes = theStrokes
    'Clear the hit test check box
    hasRecoResult = False
End Sub

Private Sub theRecognizerContext_RecognitionWithAlternates( _
ByVal RecognitionResult As IInkRecognitionResult, _
ByVal CustomData As Variant, _
ByVal RecognitionStatus As MSINKAUTLib.InkRecognitionStatus)
    Set theRecognitionResult = RecognitionResult
    'Update the text box with the top result
    Text1.Text = theRecognitionResult.TopString
    hasRecoResult = True
End Sub

Private Sub Text1_MouseUp( _
Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim hitStrokes As InkStrokes
    Dim AltStrokes As InkStrokes
    ' Convert the mouse down to ink space coordinates
    If hasRecoResult Then
        'Get the strokes matching the selection and color them red.
        On Error Resume Next
        Set AltStrokes = _
            theRecognitionResult.TopAlternate.GetStrokesFromTextRange( _
                Text1.SelStart, Text1.SelLength)
        Dim theStroke As IInkStrokeDisp
        For Each theStroke In theInkCollector.Ink.Strokes
            theStroke.DrawingAttributes.Color = RGB(0, 0, 0)
        Next
        For Each theStroke In AltStrokes
            theStroke.DrawingAttributes.Color = RGB(255, 0, 0)
        Next
        Form1.Refresh
    End If
End Sub


Private Sub theInkCollector_Stroke( _
ByVal Cursor As MSINKAUTLib.IInkCursor, _
ByVal Stroke As MSINKAUTLib.IInkStrokeDisp, _
Cancel As Boolean)
    'When a new stroke is collected, add it to
    'the RecognizerContext's strokes collection
    theStrokes.Add Stroke
    'Tell the RecognizerContext to recognize
    theRecognizerContext.BackgroundRecognizeWithAlternates
End Sub

Applies To