Tired of googling. How to set a global hook to catch WM_MENUSELECT.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Tired of googling. How to set a global hook to catch WM_MENUSELECT.

  1. #1
    Join Date
    Nov 2011
    Posts
    8

    Tired of googling. How to set a global hook to catch WM_MENUSELECT.

    Hi,

    I have a global hook system that uses a dll.
    I can install hooks for everything under the sun and my hookproc will see what I expect.

    I cannot for the life of me however install a hook and get WM_MENUSELECT coming through to me.
    I disparately need to spy on the user and know when file, save is selected, But no joy just yet.

    In the below example the first argument for SetWindowHookEx is WH_MOUSE which gives me mouse messages
    If I change that to WH_Keyboard, then I get keyboard stuff.

    What do I do to see WM_MENUSELECT ? Which is supposed to show the actual menu text which would be perfecto
    if only it would work for me.

    Hook Set:

    HINSTANCE hDLL;
    hDLL=LoadLibrary(reinterpret_cast<LPCSTR>("HookDll"));
    CBCRMaster::hkbd=SetWindowsHookEx(WH_MOUSE,(HOOKPROC)CBCRMaster::HookProc,hDLL,0);


    Thanks in advance,

    :Ron

  2. #2
    Join Date
    Apr 1999
    Posts
    27,423

    Re: Tired of googling. How to set a global hook to catch WM_MENUSELECT.

    Review your code.

    Why are you casting to an LPCSTR string here?
    Code:
    	hDLL=LoadLibrary(reinterpret_cast<LPCSTR>("HookDll"));
    What's wrong with just doing this?
    Code:
    	hDLL=LoadLibrary("HookDll");
    Second, why aren't you checking if hDLL is NULL? If the hDLL is NULL, then you're calling SetWindowsHookEx with a NULL instance, and calling it with a NULL instance changes how it behaves.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Nov 2011
    Posts
    8

    Re: Tired of googling. How to set a global hook to catch WM_MENUSELECT.

    That's not what I asked about. >:

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,763

    Re: Tired of googling. How to set a global hook to catch WM_MENUSELECT.

    You want WH_CALLWNDPROC or WH_CALLWNDPROCRET depending whether you want to trap before or after the program has processed the message.

  5. #5
    Join Date
    Nov 2011
    Posts
    8

    Re: Tired of googling. How to set a global hook to catch WM_MENUSELECT.

    Quote Originally Posted by OReubens View Post
    You want WH_CALLWNDPROC or WH_CALLWNDPROCRET depending whether you want to trap before or after the program has processed the message.
    Thanks to you, I have it working now.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center