CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2020
    Posts
    2

    SetWindowsHookEx stops receiving WH_MOUSE_LL notifications after focus lost

    Hi, I found this forum by stumbling onto the similar question here.
    The difference is, that in my case I have a SetWindowsHookEx in a simple c++ program, not a dll. The program creates an SDL2 window. But when that window loses focus, the SetWindowsHookEx stops receiving WH_MOUSE_LL messages.
    I tried to include the code snippet suggested by Igor Vartanov in the link above, but it did not help in my case.

    Any suggestion on how to make SetWindowsHookEx continue receiving WH_MOUSE_LL messages after focus of the SDL2 window is lost?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: SetWindowsHookEx stops receiving WH_MOUSE_LL notifications after focus lost

    Your hook doesn't stop working per se, it's just that Windows quits sending mouse messages to your window when it's lost focus.

    You have at least two options:
    1) keep your app in focus
    2) use a global hook

  3. #3
    Join Date
    Nov 2020
    Posts
    1

    Re: SetWindowsHookEx stops receiving WH_MOUSE_LL notifications after focus lost

    i have the same issue but where to find global hook

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: SetWindowsHookEx stops receiving WH_MOUSE_LL notifications after focus lost

    Re global hooks. See https://docs.microsoft.com/en-us/win...sg/using-hooks

    The global hook has to be in a separate dll.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Oct 2020
    Posts
    2

    Re: SetWindowsHookEx stops receiving WH_MOUSE_LL notifications after focus lost

    Just in case if more people encounter this problem -- in my case the issue could be resolved as follows:
    Windows stops sending updates to the hook (normal one, not global) if the focus is lost to a window that is running with administrator permissions while our program with the hook is running with a regular user permissions. The solution in that case was to simply start our program with administrator permissions as well, then updates are sent to the hook even after focus is lost.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured