Hook WM_GESTURE message RRS feed

  • Question

  • Hello.

    I've tried to global hook WM_GESTURE message. Hook message itself is done but I couldn't get gesture info.

    Whenever I tried GetGestureInfo with lParm I've got, it returned error code 6 which is invalid_handle.

    Accoring to this document:

    [The application creates an HGESTUREINFO handle immediately before the WindowProc is called. An application cannot save the HGESTUREINFO handle for later use. The lParam value of WM_GESTURE is meaningless outside the window process, as the HGESTUREINFO handle does not become valid until DispatchMessage delivers the message to the window process.]

    So It seems when I get the message in hook dll, lParam is not yet created or deleted.

    Then how can I get correct information while hook?

    Any ideas?


    Saturday, May 1, 2010 3:14 AM

All replies

  • Perhaps you're doing your research in the wrong library...

    These docs should be helpful.



    Wednesday, May 5, 2010 12:03 AM
  • Serenobs,

    I am currently looking into doing the same thing and am also getting an invalid handle exception. Any update on if/how you managed to work around this?

    Tuesday, May 24, 2011 8:15 PM
  • One common thing that can cause this to happen is not allocating the memory you need for the message.  The following code is the template that I use:


      GESTUREINFO gi; 
      ZeroMemory(&gi, sizeof(GESTUREINFO));
      gi.cbSize = sizeof(GESTUREINFO);
      BOOL bResult = GetGestureInfo((HGESTUREINFO)lParam, &gi);
      BOOL bHandled = FALSE;

    • Proposed as answer by Joe Wac Friday, January 13, 2012 9:14 PM
    • Unproposed as answer by Joe Wac Friday, January 13, 2012 9:15 PM
    Monday, June 6, 2011 6:03 PM
  • Sorry if this is an old thread, but I have been able to get the gesture info, but NOT able to hook for all threads in the processes. Can you send me your code that shows how to set it up?


    Here is my code in my DLL, but the only window that gets hooked is the window that initially opens the DLL and calls this function. Additionally, I do not seem to be getting WM_GESTURENOTIFY messages. How can I register for them?


        __declspec(dllexport) bool setGestureHook(void)
            g_hookGesture = SetWindowsHookEx(
            if (g_hookGesture) OutputDebugString(L"Gestures Hooked\n");
            return g_hookGesture != 0;

    Joe Waclawski
    Friday, January 13, 2012 9:14 PM