Draw Method [InkRenderer Class]

Draw Method [InkRenderer Class]

Draws ink strokes using the known device context.

Declaration

[C++]

HRESULT Draw (
    [in] long hdc,
    [in] IInkStrokes* strokes
);

[Microsoft® Visual Basic® 6.0]

Public Sub Draw( _
    hdc As Long, _
    strokes As InkStrokes _
)

Parameters

hdc

[in] Specifies the hWnd of the device context on which to draw.

strokes

[in] Specifies the strokes to draw.

Return Value

HRESULT value Description
S_OK Success.
E_POINTER A parameter contained an invalid pointer.
E_INK_MISMATCHED_INK_OBJECT The strokes parameter is associated with a different InkDisp object.
E_INVALIDARG An argument is invalid.
E_INK_INCOMPATIBLE_OBJECT The stroke or the drawingAttributes parameter does not point to a valid object.
E_INK_EXCEPTION An exception occurred inside the method.
E_UNEXPECTED Unexpected parameter or property type.

Remarks

The pen width is multiplied (or scaled) by the square root of the determinant of the view transform.

Note: If you have not set the pen width explicitly, it is 53 by default. You must multiply the pen width by the square root of the determinant to yield the correct bounding box. The height and width of the bounding box are expanded by half this amount in each direction.

For example, consider that the pen width is 53, the square root of the determinant is 50, and the bounding box is (0,0,1000,1000). The pen width adjustment to the bounding box in each direction is calculated as (53*50)/2, and the right and bottom sides are incremented by one. This results in a rendered bounding box of (-1325,-1325,2326,2326).

Note: Use the DrawStroke method to draw a single stroke.

The InkRenderer forces the viewport and window origins to 0,0. Any existing settings are saved and restored, but is not used by the InkRenderer. To perform scrolling, use the InkRenderer object's view and object transform methods.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example shows a way to do a hit test on ink strokes. Starting with a standard .exe application and adding a reference to the Tablet PC Type Library, this example adds a check box, CheckHitTestMode, which toggles between inking and hit testing with the mouse or pen. When the box is checked, MouseMove events are used to store the mouse location information and force a repaint. The Paint event handler redraws each stroke in blue if part of it is inside the hit test radius, and black otherwise. A circle is drawn around the mouse pointer in red if the hit test radius intersects any strokes, and black if it does not. The Paint event uses the Draw method of the InkRenderer in the InkCollector to redraw when in hit test mode, rather than letting the ink draw itself with the AutoRedraw property set to True.

        Option Explicit
Dim mouseX As Long
Dim mouseY As Long
Dim inkX As Long
Dim inkY As Long
Dim inkRadius As Long
Dim theInkCollector As InkCollector

Private Sub CheckHitTestMode_Click()
    'Toggle the ink collection mode
    theInkCollector.Enabled = Not theInkCollector.Enabled
    theInkCollector.AutoRedraw = Not theInkCollector.AutoRedraw
    Refresh
End Sub

Private Sub Form_Load()
    'Set ScaleMode to pixels to make calculating easier
    Me.ScaleMode = vbPixels
    'Set up the InkCollector
    Set theInkCollector = New InkCollector
    theInkCollector.hWnd = Me.hWnd
    theInkCollector.Enabled = True
    'Preload the inkRadius to the inkspace equivalent of
    '20 pixels
    inkRadius = 20
    theInkCollector.Renderer.PixelToInkSpace Me.hDC, inkRadius, 0
    'Start with the hit test mode turned off
    CheckHitTestMode.Value = 0
End Sub

Private Sub Form_MouseMove( _
Button As Integer, Shift As Integer, X As Single, Y As Single)
    If CheckHitTestMode.Value = 1 Then
        mouseX = X
        mouseY = Y
        inkX = X
        inkY = Y
        theInkCollector.Renderer.PixelToInkSpace Me.hDC, inkX, inkY
        Refresh
    End If
End Sub

Private Sub Form_Paint()
    If CheckHitTestMode.Value = 1 Then
        'Set the standard ink drawing attributes to black
        Dim theDrawingAttributes As New InkDrawingAttributes
        theDrawingAttributes.Color = vbBlack
        theInkCollector.Ink.Strokes.ModifyDrawingAttributes theDrawingAttributes
        theInkCollector.Renderer.Draw Me.hDC, theInkCollector.Ink.Strokes
        'Get the collection of hit strokes
        Dim hitStrokes As InkStrokes
        Set hitStrokes = _
            theInkCollector.Ink.HitTestCircle(inkX, inkY, inkRadius)
        If hitStrokes.Count > 0 Then
            'Draw the hit test circle in red
            Me.ForeColor = vbRed
            'Draw the hit strokes in blue
            theDrawingAttributes.Color = vbBlue
            Dim theStroke As IInkStrokeDisp
            For Each theStroke In hitStrokes
                theInkCollector.Renderer.DrawStroke Me.hDC, theStroke, theDrawingAttributes
            Next
        Else
            'Draw the hit test circle in black
            Me.ForeColor = vbBlack
        End If
        'Draw the strokes, and the hit test circle
        Circle (mouseX, mouseY), 20
    End If
End Sub

Applies To