GetStrokesFromStrokeRanges Method
GetStrokesFromStrokeRanges Method |
Returns the smallest InkStrokes collection that contains a known input InkStrokes collection and for which the IInkRecognizer object can provide alternates.
Declaration
[C++]
HRESULT GetStrokesFromStrokeRanges (
[in] IInkStrokes* strokes,
[out, retval] IInkStrokes **GetStrokesFromStrokeRanges
);
[Microsoft® Visual Basic® 6.0]
Public Function GetStrokesFromStrokeRanges( _
strokes As InkStrokes _
) As InkStrokes
Parameters
strokes
[in] The collection of stroke objects to use to find the smallest stroke collection of the recognition result alternate that contains this collection.
GetStrokesFromStrokeRanges
[out, retval] Returns the smallest collection of strokes that contains a known input collection of strokes and for which the recognizer can provide alternates.
Return Value
HRESULT value | Description |
---|---|
S_OK | Success. |
E_POINTER | A parameter contained an invalid pointer. |
E_INK_EXCEPTION | An exception occurred inside the method. |
E_INK_MISMATCHED_INK_OBJECT | The strokes parameter is associated with a different Ink object. |
E_FAIL | An unspecified error occurred. |
Remarks
The returned collection may match the input collection, or it may be larger if the input collection matches only part of the smallest recognition result that includes all of the input strokes.
This method is most useful for single-click word selection. For example, to return the strokes that make up the word you clicked, you can click a stroke, call the HitTest method of the IInkStrokeDisp object to retrieve the stroke that was clicked, and then call GetStrokesFromStrokeRanges.
The stroke ranges are valid until the InkDisp object is modified.
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 clicking the mouse in the drawing space of Form1, where the ink strokes have been recognized and the result is in an IInkRecognitionResult object, theRecognitionResult. This example starts with a standard .exe application, adds a reference to the Microsoft Tablet PC Type Library, and has a text box Text1 and a check box HitTestMode added to the form. When the check box is unchecked, ink is collected and recognized, with the top alternate placed in the text box. When the check box is checked, a click with the mouse or a tap with the pen finds the collection of strokes within a hit test radius of 200 ink space units 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 HitTestMode_Click()
theInkCollector.Enabled = Not theInkCollector.Enabled
End Sub
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
HitTestMode.Value = 0
hasRecoResult = False
End Sub
Private Sub Form_MouseDown( _
Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim inkX As Long
Dim inkY As Long
Dim hitStrokes As InkStrokes
Dim AltStrokes As InkStrokes
' Convert the mouse down to ink space coordinates
If hasRecoResult And HitTestMode.Value = 1 Then
inkX = CLng(X)
inkY = CLng(Y)
theInkCollector.Renderer.PixelToInkSpace Form1.hDC, inkX, inkY
'Get the stroke set hit by the mouse (within a radius
'of 200 HIMETRIC) and color it red.
Set hitStrokes = theInkCollector.ink.HitTestCircle(inkX, inkY, 200)
If hitStrokes.Count > 0 Then
Set AltStrokes = _
theRecognitionResult.TopAlternate.GetStrokesFromStrokeRanges(hitStrokes)
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 If
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 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