1

I've been searching through the Windows API, looking for a way to intercept all WM_MOUSESCROLL messages before they hit their perspective message queues. After intercepting I need to change a few things about them and send them to a different [or the same] message queue.

I need to do this fairly efficiently as it will be running on top of a fairly large application.

Any Ideas on how I can achieve this? I've yet to find a way.

Martin
  • 152
  • 10
  • Do you mean `WM_MOUSEWHEEL`? There is no `WM_MOUSESCROLL` message. Also, when you say *all*, do you mean all for your thread, all for your process, or all throughout the system? – Raymond Chen Feb 27 '12 at 23:03
  • You are correct, I meant WM_MOUSEWHEEL, and I mean ALL, all throughout the system, and I really would like to be the first to receive it. – Martin Feb 28 '12 at 15:22
  • There's no way you can guarantee being the first to receive it (by application of the "What if two programs did this?" principle). But if you use a low-level hook, you'll get it before the input system dispatches it, which may be good enough. – Raymond Chen Feb 28 '12 at 17:01

2 Answers2

2

Your best bet is an unmanaged interception using a low level mouse event hook. see this MSKB article for more info.

Necrolis
  • 25,836
  • 3
  • 63
  • 101
  • 2
    I summarized that MS article once in the following SO answer: http://stackoverflow.com/questions/7497024/how-to-detect-mouse-clicks/7497173#7497173 – Christophe Geers Feb 28 '12 at 08:41
  • @ChristopheGeers: thats awesome, much more readable than the MS one – Necrolis Feb 28 '12 at 09:09
  • I tried this and it works great, 50% of the time though. Sometimes I will receive the message before the the window I'm trying to modify these messages for, sometimes after. This changes the applications desired behavior. Btw, I don't own the window, however, it's handle is easily accessible. – Martin Feb 28 '12 at 15:25
  • @AdmiralNelson: then there is something wrong with the hook, as the LL one is guaranteed to be called before its posted to the message queue. you may also want to try `WH_CALLWNDPROC`, which gets all messages before they get dispatched to the WndProc. – Necrolis Feb 28 '12 at 15:32
0

When using MFC you can use PreTranslateMessage, or search for the WndProc function in a custom framework and see if it provides similar functionality. Otherwise the mouse hooking is good idea. Especially when you want to do it globally.

demorge
  • 1,097
  • 1
  • 7
  • 17