Receiving Stylus Input

In many Windows CE–based applications, the user interacts with an application by using a stylus and a touch screen. The stylus and touch screen provide a direct and intuitive alternative to a mouse.

The stylus generates an input event when the user touches the screen with a stylus or moves the stylus when the tip is touching the screen. To an application, stylus input is a subset of mouse input. When a user presses and releases a stylus on a screen, the application processes these events as a click of the left mouse button. When a user moves the stylus across the screen, the application processes this as a mouse move event.

Stylus input events in a window are posted to the message queue of the thread that created the window. A window receives a stylus message when a stylus event occurs within the window client area. When the user presses the stylus to the screen, the window receives a WM_LBUTTONDOWN message. When the stylus is lifted from the screen, the window receives a WM_LBUTTONUP message. Occasionally, a window receives a WM_LBUTTONDBLCLK message instead of a WM_LBUTTONDOWN message. This occurs under the following conditions:

If a user moves the stylus while pressing it to the screen, Windows CE generates a WM_MOUSEMOVE message.

The following table shows style input messages that are supported by Windows CE.

Message
Description
WM_LBUTTONDBLCLK The user double-tapped the screen.
WM_LBUTTONDOWN The user pressed the screen.
WM_LBUTTONUP The user released the stylus from the screen.
WM_MOUSEMOVE The user moved the stylus while the tip was pressed to the screen.

The lParam parameter of a stylus message indicates the position of the stylus tip. The low-order word is the x-coordinate and the high-order word is the y-coordinate. The coordinates are specified in the client coordinates. In the client-coordinate system, all points are specified relative to the upper-left corner of the client area.

The wParam parameter contains flags that indicate the status of the other stylus buttons and the CTRL and SHIFT keys at the stylus event time. Check for these flags when the way you process a stylus event depends on the state of another stylus button or on the CTRL or SHIFT key. The following table shows the flags that you can set in the wParam parameter.

Value
Description
MK_CONTROL The CTRL key is down.
MK_LBUTTON The stylus is touching the screen.
MK_SHIFT The SHIFT key is down.