Chapter 13. WH_MOUSE and WH_MOUSE_LL
This chapter deals first with the
and then with the
WH_MOUSE_LL hook. The
LL stands for low-level. This chapter describes
these hooks and discusses how the Windows messaging system handles
mouse messages. I will provide examples using each hook.
How Mouse Messaging Operates
Unlike with keyboard messages, the system must be able to send mouse messages to any visible window in the system, even if it is not the active window. We can see this by using Spy++ to view mouse messages on a system-wide level. Start Spy++ and click the Spy → Messages . . . menu item. The Message Options dialog will appear. Check the All Windows In System checkbox on the Windows tab, and check the Mouse checkbox on the Messages tab. Finally, click the OK button. This will start Spy++ recording mouse messages. As you move the mouse cursor over windows in the system, you will see that a window does not have to be active to receive mouse messages. The Spy++ output looks similar to this:
WM_SETCURSOR (Sent) WM_SETCURSOR (Returned) WM_MOUSEMOVE (Posted)
This series of messages is repeated over and over again as the user moves the mouse across any visible windows on the desktop. Right- or left-clicking any visible windows also sends the appropriate mouse messages to that window.
A window does have to be visible to the mouse cursor to receive messages, though. Any window or part of a window hidden behind another window in the Z-order will not be able to receive mouse ...