Share via


BackgroundRecognizeWithAlternates Method

BackgroundRecognizeWithAlternates Method

Causes the IInkRecognizer object to recognize the associated strokes collection and fire a RecognitionWithAlternates event when recognition is complete.

Declaration

[C++]

public void BackgroundRecognizeWithAlternates(
    [in, optional] VARIANT customData
);

[Microsoft® Visual Basic® 6.0]

Public Sub BackgroundRecognizeWithAlternates( _
    [customData] _
)

Parameters

customData

[in, optional] Specifies any application-defined data that is available to the application in the RecognitionWithAlternates event. This parameter may be a VARIANT of type VT_EMPTY or VT_NULL if no data needs to be passed. The default value is NULL.

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

Return Value

HRESULT value Description
S_OK Success.
E_OUTOFMEMORY Cannot allocate memory to complete the operation.
E_INK_NO_STROKES_TO_RECOGNIZE No strokes exist.
E_INK_EXCEPTION An exception occurred inside the method.

Remarks

This method specifies that ink recognition is performed asynchronously.

To perform recognition that includes only the best result string with no alternates, call the BackgroundRecognize method.

The RecognitionWithAlternates event is not raised if the recognizer does not recognize any alternates.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 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 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