Share via


BackgroundRecognize Method

BackgroundRecognize Method

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

Declaration

[C++]

HRESULT BackgroundRecognize(
    [in, optional] VARIANT customData
);

[Microsoft® Visual Basic® 6.0]

Public Sub BackgroundRecognize( _
    [customData] _
)

Parameters

customData

[in, optional] Specifies any application-defined data that is available to the application in the Recognition 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 recognize ink synchronously, call the Recognize method.

This method recognizes only the best result string. Alternates are not created. To perform recognition that creates a list of available alternates, call the BackgroundRecognizeWithAlternates method.

The Recognition event is not raised if the recognizer does not recognize anything.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example tracks each stroke that is made and calls the BackgroundRecognize method, which subsequently causes a recognition event to occur. This sample application began with a simple form and added a text box named TextBox1, as well as a reference to the Tablet PC Type Library. The results of the recognition appear in the text box.

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_Recognition( _
ByVal RecognizedString As String, _
ByVal CustomData As Variant, _
ByVal RecognitionStatus As MSINKAUTLib.InkRecognitionStatus)
    'Update the text box with the top result
    TextBox1.Text = RecognizedString
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.BackgroundRecognize
End Sub

Applies To