Partager via


RecognitionWithAlternates Event

RecognitionWithAlternates Event

Occurs when the InkRecognizerContext has generated results after calling the BackgroundRecognizeWithAlternates method.

Declaration

[C++]

void RecognitionWithAlternates(
    [in] IInkRecognitionResult* RecognitionResult,
    [in] VARIANT CustomData,
    [in] InkRecognitionStatus RecognitionStatus
);

[Microsoft® Visual Basic® 6.0]

Public Event RecognitionWithAlternates( _
    RecognitionResult As IInkRecognitionResult, _
    CustomData, _
    RecognitionStatus As InkRecognitionStatus _
)

Parameters

RecognitionResult

[in] The recognition result from the event.

CustomData

[in] The custom data for the recognition result.

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

RecognitionStatus

[in] The recognition status as of the most recent recognition result.

Remarks

The behavior of the application programming interface (API) is unpredictable if you try to gain access to the original RecognizerContext object from the recognition event handler. Do not attempt to do this. Instead, if you need to do this, create a flag and set it in the Recognition event handler. Then you can poll that flag to determine when to change the RecognizerContext properties outside of the event handler.

This event method is defined in the _IInkRecognitionEvents interface. The _IInkRecognitionEvents interface implements the IDispatch Leave Site interface with an identifier of DISPID_IRERecognitionWithAlternates.

Example

[Visual Basic 6.0]

This Visual Basic 6 example demonstrates using background recognition with alternates with a call to the recognizer as each stroke is collected. It then displays the top results as they are generated, along with several of the alternates in descending order of confidence in a list box. This sample application began with a simple form and added a list box named List1, along with a reference to the Microsoft Tablet PC Type Library.

Option Explicit
Dim WithEvents theInkCollector As InkCollector
Dim WithEvents theRecognizerContext As InkRecognizerContext
Dim theStrokes As InkStrokes

Private Sub Form_Load()
    '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
End Sub

Private Sub theRecognizerContext_RecognitionWithAlternates( _
ByVal RecognitionResult As MSINKAUTLib.IInkRecognitionResult, _
ByVal CustomData As Variant, _
ByVal RecognitionStatus As MSINKAUTLib.InkRecognitionStatus)
    'Clear the list box
    List1.Clear
    'Get the set of alternates from the entire
    'result selection.
    Dim theRecognitionAlternates As IInkRecognitionAlternates
    Set theRecognitionAlternates = RecognitionResult.AlternatesFromSelection(0, -1, 5)
    'Update the list box with the alternates
    Dim theRecognitionAlternate As IInkRecognitionAlternate
    For Each theRecognitionAlternate In theRecognitionAlternates
        List1.AddItem (theRecognitionAlternate.String)
    Next
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