0

When using the Win32 API message loop (or any higher level abstraction of the same such as System.Windows.Forms.IMessageFilter) to get a message, how do I find out who/which control/which component/which piece of code posted the WM_MOUSEMOVE?

Does that even make sense in the context of Win32? Something akin to the object sender in .NET events.

I checked the documentation for WM_MOUSEMOVE and I can't find anything. It's been a decade I haven't used Win32 API extensively since.

Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336

1 Answers1

2

All window messages are sent to a specific HWND. That's the receiver. The sender, for window messages, is the operating system as it generates the window message for the specific window when it decides that a message should be sent to the window.

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
  • I want to distinguish between "user generated mouse moves" and those generated or sent by my own app. How would I do that? – Water Cooler v2 Jan 14 '14 at 09:12
  • 1
    @WaterCoolerv2 It's a little late to ask that question. You've already asked a quite different one. If you want to know how to distinguish between those types of messages, you need to ask that specific question. – David Heffernan Jan 14 '14 at 09:13
  • From my knowledge I'd say you can not. – Thorsten Dittmar Jan 14 '14 at 09:14
  • @WaterCoolerv2 Instead of sending yourself a WM_MOUSEMOVE you could send your own user message (WM_USER + x) and handle it as if it *was* a mouse move, however! – Thorsten Dittmar Jan 14 '14 at 09:15
  • @ThorstenDittmar Thank you. That is certainly something to think about. Though, I am getting the feeling that that is an illusive pathway. My app window will have to first receive WM_MOUSEMOVE and then translate or dispatch that as some WM_MY_OWN_THING, and then in the same filter/FrameWnd/WndProc/message loop, I have to read that custom message. That wouldn't guarantee that WM_MOUSEMOVE's are then system generated. But definitely worth thinking about. Thank you. – Water Cooler v2 Jan 14 '14 at 09:31
  • @ThorstenDittmar That is precisely how I would do it. – David Heffernan Jan 14 '14 at 09:33
  • @WaterCoolerv2 No, that's not what is meant at all. If you app needs to generate mouse move, it sends `(WM_USER+x)` messages. And then your window re-sends `WM_MOUSEMOVE` but now it knows that the sender was the app. – David Heffernan Jan 14 '14 at 09:34
  • Don't use `WM_USER+x` for communication between applications. This range is reserved for control implementations. Go with `WM_APP+x` instead. There's also one more point worth mentioning: `WM_MOUSEMOVE` messages are different from other messages. They are not generated by the system and posted to a message queue. They are rather generated on-the-fly, whenever an application calls `GetMessage` and the message queue is empty (and an internal flag that the mouse moved is set). Posting `WM_MOUSEMOVE` messages is asking for trouble. – IInspectable Jan 14 '14 at 11:36