Freigeben über


ModifyTopAlternate MethodMethod

ModifyTopAlternate MethodMethod

Changes the top alternate of a recognition result by using the specified alternate.

Declaration

[C++]

HRESULT ModifyTopAlternate (
    [in] IInkRecognitionAlternate* alternate
);

[Microsoft® Visual Basic® 6.0]

Public Sub ModifyTopAlternate( _
    alternate As IInkRecognitionAlternate _
)

Parameters

alternate

[in] The IInkRecognitionAlternate to use to modify the top alternate.

Return Value

HRESULT value Description
S_OK Success.
TPC_E_NOT_RELEVANT The lattice does not contain data.
E_POINTER A parameter contained an invalid pointer.
E_INVALIDARG The alternate does not match the known range, or it was not obtained from this lattice.
E_INK_EXCEPTION An exception occurred while processing.
E_OUTOFMEMORY Cannot allocate memory to complete the operation.

Remarks

By default, the best result string of the recognition result corresponds to the top alternate. However, you can use this method to specify that alternates other than the top alternate are used in the result. When you choose an alternate other than the top alternate, you are essentially choosing a different path through the lattice of alternates that are associated with the results.

To retrieve the alternates that can be used to modify the recognition result, call the GetAlternatesFromSelection method.

Note: A call to ModifyTopAlternateMethod may modify the TopString and TopAlternate properties.

The alternate used in the function can be a word alternate in an entire sentence. For example, an alternate obtained by using GetAlternatesFromSelection (0,5) for "Hello World" only changes the "Hello" part of the word leaving the "World" part intact.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example recognizes strokes as they are made and uses a list box to report the first five alternates of the IInkRecognitionResult, and allows the user to select another alternate as the TopAlternate by double-clicking that alternates string in the list box, using ModifyTopAlternateMethod which changes the order of the alternates. The example calls SetResultOnStrokes to save the recognition result between the recognition event and a double-click event. This example was created as a standard .exe application with a reference added to the Microsoft Tablet PC Type Library and a list box, List1, added to the form.

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
    'Initialize the recognizer's strokes
    'and assign them to the new RecognizerContext
    Set theRecognizerContext = New InkRecognizerContext
    Set theStrokes = theInkCollector.Ink.Strokes
    Set theRecognizerContext.Strokes = theStrokes
End Sub

Private Sub List1_DblClick()
    'Modify the top alternate to be the one double-clicked
    Dim theRecognitionAlternates As IInkRecognitionAlternates
    Dim theRecognitionResult As IInkRecognitionResult
    Set theRecognitionAlternates = theStrokes.RecognitionResult. _
        AlternatesFromSelection(0, -1, 5)
    Set theRecognitionResult = theStrokes.RecognitionResult
    theRecognitionResult.ModifyTopAlternate theRecognitionAlternates(List1.ListIndex)
    theRecognitionResult.SetResultOnStrokes
    'Update the list box with the new order of alternates
    List1.Clear
    Set theRecognitionAlternates = theStrokes.RecognitionResult. _
        AlternatesFromSelection(0, -1, 5)
    Dim theRecognitionAlternate As IInkRecognitionAlternate
    For Each theRecognitionAlternate In theRecognitionAlternates
        List1.AddItem (theRecognitionAlternate.String)
    Next
End Sub

Private Sub theRecognizerContext_RecognitionWithAlternates( _
ByVal RecognitionResult As MSINKAUTLib.IInkRecognitionResult, _
ByVal CustomData As Variant, _
ByVal RecognitionStatus As MSINKAUTLib.InkRecognitionStatus)
    'Update the list box with the alternates
    List1.Clear
    Dim theRecognitionAlternates As IInkRecognitionAlternates
    Set theRecognitionAlternates = RecognitionResult.AlternatesFromSelection(0, -1, 5)
    Dim theRecognitionAlternate As IInkRecognitionAlternate
    For Each theRecognitionAlternate In theRecognitionAlternates
        List1.AddItem (theRecognitionAlternate.String)
    Next
    'Save the recognition results with the strokes
    RecognitionResult.SetResultOnStrokes
End Sub

Private Sub theInkCollector_Stroke( _
ByVal Cursor As MSINKAUTLib.IInkCursor, _
ByVal Stroke As MSINKAUTLib.IInkStrokeDisp, _
Cancel As Boolean)
    'Tell the RecognizerContext to recognize the strokes
    theStrokes.Add Stroke
    theRecognizerContext.BackgroundRecognizeWithAlternates
End Sub

Applies To