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

    Keeping hook thread alive?

    In a C++ program I'm writing I need a mouse hook active to selectively filter event messages at certain points. Putting the hook in the main thread results in significant mouse lag so I created a background thread and put the hook there.

    The problem is, if I keep the background thread open with a while(1){} loop I still get the lag. Using Sleep() in the loop also causes lag, though in a slightly different way.

    One thing I have found that works perfectly is opening a MessageBox() in the hook thread (no loop involved). It keeps the thread from returning and lets the mouse remain completely responsive. Now I just have a superfluous message box on my screen, and closing it ends the mouse hook.

    What are my other options here? I'm fairly new to the Windows API and don't have a thorough knowledge of C++ built-in functions. I've search quite a bit but haven't found a solution, though I have a feeling the answer will be embarrassingly obvious.

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

    Re: Keeping hook thread alive?

    You need to run message loop in this worker 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
  •  





Click Here to Expand Forum to Full Width

Featured