How to get all mousemove events while main thread is busy Windows MFC C++

Viewed 203

I have a long CPU operation on a mousemove event. It seems like no new mousemove events are sent to my application during that time, making for big jumps in mouse position.

I thought mouseevents would build up in a queue and then all get sent to my app, but this does not seem to be the case.

I would like as high resolution of mousemove events as is possible from the device - whether or not the app is busy processing something.

Should I put my application in a worker thread, and let my main thread just process events? Is there a simpler way to see 'raw' mouse input.

1 Answers

You have a few options:

  • As you mentioned, put your processing in a worker thread and let Windows messages pump in your main thread. This is probably the most conventional method, the most logical design.
  • Use GetCursorPos and GetAsyncKeyState to get mouse state whenever you want it, without depending on the Windows message loop. In other words, interrupt your busy task every N milliseconds to poll and record mouse state. I don't recommend this because you'll be polling, bypassing the system's message handling.
  • Pump the message loop whenever you want to allow messages through. Think DoEvents from Visual Basic. I just don't recommend this; it's one of these things that "feels simple" but actually adds the kind of complexity that will make you just want to abandon your code and rewrite it correctly.
Related