次の方法で共有


HitTest(Point, Single) Method [InkDisp Class]

HitTest(Point, Single) Method [InkDisp Class]

Retrieves the InkStrokes collection that are either completely inside or intersected by a known circle.

Declaration

[C++]

HRESULT HitTestCircle (
    [in] long x,
    [in] long y,
    [in] float radius,
    [out, retval] IInkStrokes **Strokes
);

[Microsoft® Visual Basic® 6.0]

Public Function HitTestCircle( _
    x As Long, _
    y As Long, _
    radius As Single _
) As InkStrokes;

Parameters

radius

[in] The radius of the circle to use in the hit test, in ink space units.

x

[in] The x-position of the center of the hit test circle in ink space units.

y

[in] The y-position of the center of the hit test circle in ink space units.

Strokes

[out] Returns the collection of strokes that are either completely inside or intersected by the specified circle.

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_INVALIDARG Invalid display handle.
E_UNEXPECTED Unexpected parameter or property type.

Remarks

If a stroke intersects the circle, the complete stroke is returned.

The method computes the intersection, considering the full set of drawing attributes that apply to the stroke, including the full pen width, Bezier smoothing (if present), and shape of the pen tip.

After a rotation or shear transform has been performed on a stroke or a collection of strokes, the transformed x- and y-coordinates are no longer concentric with the original coordinates. Because of this, the radius argument should not be calculated from the x- or y-coordinates.

To determine which points of a known stroke intersect the test area, call the HitTest method of the IInkStrokeDisp object.

The application must always pass in a destination pointer for the resulting collection of strokes. If there are no intersections, the collection has a count of zero.

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 will use HitTest(Point, Single) to find the collection of strokes within a hit test radius of 200 ink space units and color 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

Applies To