Bagikan melalui


NewPackets Event

NewPackets Event

Occurs when the ink collector receives packets.

Declaration

[C++]

void NewPackets(
    [in] IInkCursor* Cursor,
    [in] IInkStrokeDisp* Stroke,
    [in] long PacketCount,
    [in, out] VARIANT* PacketData
);

[Microsoft® Visual Basic® 6.0]

Public Event NewPackets( _
    Cursor As IInkCursor, _
    Stroke As IInkStrokeDisp, _
    PacketCount As Long, _
    PacketData _
)

Parameters

Cursor

[in] The IInkCursor object that generated the NewInAirPackets event.

Stroke

[in] Specifies the IInkStrokeDisp object.

PacketCount

[in] The number of packets received for a IInkStrokeDisp object.

PacketData

[in, out] An array that contains the the selected data for the packet.

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

Remarks

Packets are received while a stroke is being collected. Packet events occur rapidly, and a NewPackets event handler must be fast or performance suffers.

This event method is defined in the _IInkCollectorEvents, _IInkOverlayEvents, and _IInkPictureEvents dispatch-only interfaces (dispinterfaces) with an ID of DISPID_ICENewPackets.

This event should be used carefully as it could have an adverse effect on ink performance if too much code is executed in the event handlers.

To set which properties are contained in this array, use the DesiredPacketDescription property of the ink collector object. The array that the PacketData parameter returns contains the data for those properties.

Note: Although you can modify the packet data, these modifications are not persisted or used.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example draws a rectangle on the form with a red outline when the packets in the NewPackets event are within the rectangle or with a black outline when the packets are outside the rectangle. This demonstrates how to use the packet events to control application behaviors.

Option Explicit
Dim WithEvents theInkCollector As InkCollector
Dim theInkRectangle As InkRectangle

Private Sub Form_Load()
    Set theInkCollector = New InkCollector
    theInkCollector.hWnd = Me.hWnd
    theInkCollector.Enabled = True
    Set theInkRectangle = New InkRectangle
    theInkRectangle.SetRectangle 40, 40, 120, 300
    ScaleMode = vbPixels
    Form1.Line (theInkRectangle.Left, theInkRectangle.Top)-(theInkRectangle.Right, _
        theInkRectangle.Bottom), RGB(0, 0, 0), B
    theInkCollector.SetEventInterest ICEI_NewPackets, True
End Sub

Private Sub theInkCollector_NewPackets( _
ByVal Cursor As MSINKAUTLib.IInkCursor, _
ByVal Stroke As MSINKAUTLib.IInkStrokeDisp, _
ByVal PacketCount As Long, PacketData As Variant)
    Dim packetX As Long
    Dim packetY As Long
    'There may be multiple packets of data, but we will rely on
    'the fact that there will be at least one, and its first two
    'data items are the X and Y coordinates.
    packetX = PacketData(0)
    packetY = PacketData(1)
    theInkCollector.Renderer.InkSpaceToPixel Form1.hDC, packetX, packetY
    'Draw the box in red if the packets are within it, and black if not.
    If theInkRectangle.Left < packetX And theInkRectangle.Right > packetX And _
    theInkRectangle.Top < packetY And theInkRectangle.Bottom > packetY Then
        Form1.Line (theInkRectangle.Left, theInkRectangle.Top)-(theInkRectangle.Right, _
            theInkRectangle.Bottom), RGB(255, 0, 0), B
    Else
        Form1.Line (theInkRectangle.Left, theInkRectangle.Top)-(theInkRectangle.Right, _
            theInkRectangle.Bottom), RGB(0, 0, 0), B
    End If
End Sub

Applies To