Windows Mobile 6.5

The WM_GESTURE message is sent to a window procedure to indicate that a gesture has occurred or, in the case of a pan, is in progress.

WM_GESTURE messages can be forwarded synchronously from a WndProc using the SendMessage(), SendMessageTimeout() or SendNotifyMessage () APIs.

WM_GESTURE messages cannot be forwarded from a WindowProc using PostMessage or PostThreadMessage.

The window procedure can call TKGetGestureInfo to determine the state of the gesture.

A window receives this message through its WindowProc function.

    WPARAM wParam
    LPARAM lParam


Contains the ID of the gesture command.


Contains the HGESTUREINFO handle of the gesture command.

If the application processes the gesture, it returns a non–zero value. If the application does not process the gesture, it should pass it to DefWindowProc and the return value would be the value returned by DefWindowProc.

Based on the gesture ID, you should decide whether the application should handle the gesture itself, or whether it should pass the gesture to DefWindowProc. GID_BEGIN and GID_END should always be passed to DefWindowProc. If the application processes the gesture, it does not pass the message to the default window procedure.

The following code sample shows how the gesture can be handled based on its ID.

memset(&gi, 0, sizeof(gi));
gi.cbSize = sizeof(GESTUREINFO);
if (GetGestureInfo((HGESTUREINFO)lParam, &gi))
    // Handle gesture indicated by wParam or gi.dwID
    // Error handling

The HGESTUREINFO handle is created just before the WindowProc is called. It is destroyed by returning from the window procedure. Note that an application cannot save the HGESTUREINFO handle for later use. The lParam value of WM_GESTURE is meaningless outside of the window procedure, as the HGESTUREINFO handle does not become valid until DispatchMessage delivers the message to the window procedure. Therefore, the following code sample will not work properly.

while (GetMessage(&msg, NULL, 0, 0))
    if (msg.msg == WM_GESTURE)

An unhandled WM_GESTURE message passed to DefWindowProc will be propagated to the parent window. When forwarding gesture messages between windows, avoid sending messages from parent to child windows in order to prevent closed loops from occurring.

Windows MobileWindows Mobile 6.5 and later

Community Additions