Global hooking mouse click
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Global hooking mouse click

  1. #1
    Join Date
    Jun 2009
    Posts
    6

    Global hooking mouse click

    Hello everyone,

    Iīm having a problem hooking mouse click. I want to make this hook global to 'catch' all mouse clicks (not only may appīs)
    and to stop the hook chain. I want to do this in order to have a 'dead zone' in the screen where mouse clicks are disabled.


    I compiled an external DLL with the hook procedure an used it from my application using:

    hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, "?mouseHookProc@@YGJHIJ@Z");
    hhookSysMsg = SetWindowsHookEx(WH_MOUSE_LL, hkprcSysMsg, hinstDLL,0);


    (mouseHookProcedure is a Hello World proc. that only shows a messageBox)


    When I execute the app. and click left-button the message box appears but the hook chain continues. I tried using the function callNextHookEx and passing NULL value as first parameter:

    CallNextHookEx( NULL , nCode , wParam, lParam );

    But this seems not to work on Windows NT/XP since the firts parameter of this function is ignored in the last versions of windows.

    I even tried not to call the callNextHookEx but the hook chain still continues. So my question is:

    How can I make a global mouseclick hook that catches the clik and stops the chain in WinXP?

    Thanks in advance.

  2. #2
    Join Date
    Jul 2002
    Posts
    2,526

    Re: Global hooking mouse click

    If the hook procedure processed the message, it may return a nonzero value to prevent the system from passing the message to the target window procedure.
    So, if you want to stop click handling, don't call CallNextHookEx.
    Two notes about your code. Use extern "C" in the hook dll, in this case you can use mouseHookProc name without C++ name mangling. Consider using WH_MOUSE_LL hook, which is much simpler, because it doesn't require external Dll. You can do this, if code is not running on Win95/98.

  3. #3
    Join Date
    Jun 2009
    Posts
    6

    Re: Global hooking mouse click

    Hi again,

    As far as I know (and its not too far ), if you want the hook to be global (system hook) you must do it as a DLL.

    My procedure returns a '1' value to stop the chain but it continues.

    Is it impossible to stop the chain?

  4. #4
    Join Date
    Jul 2002
    Posts
    2,526

    Re: Global hooking mouse click

    Global WH_MOUSE_LL hook does not require Dll. To stop chain, return 1 without calling CallNextHookEx.

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center