0

So, I was reading the WinApi documentation for the callback function of a low-level mouse hook and I got confused about the WPARAM parameter passed to this function.

From the Documentation about the callback function:

wParam [in]
Type: WPARAM

The identifier of the mouse message. This parameter can be one of the following messages: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_MOUSEHWHEEL, WM_RBUTTONDOWN, or WM_RBUTTONUP.

This only mentions WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_MOUSEHWHEEL, WM_RBUTTONDOWN and WM_RBUTTONUP.

But in the Documentation about the MSLLHOOKSTRUCT structure (used with low-level mouse hooks), other messages are also mentioned:

mouseData

Type: DWORD

If the message is WM_MOUSEWHEEL, the high-order word of this member is the wheel delta. The low-order word is reserved. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.

If the message is WM_XBUTTONDOWN, WM_XBUTTONUP, WM_XBUTTONDBLCLK, WM_NCXBUTTONDOWN, WM_NCXBUTTONUP, or WM_NCXBUTTONDBLCLK, the high-order word specifies which X button was pressed or released, and the low-order word is reserved. This value can be one or more of the following values. Otherwise, mouseData is not used.

Are those messages also passed in the WPARAM parameter?

thebear8
  • 194
  • 2
  • 11
  • 2
    I've never even worked out what an 'X' button is :) But I imagine everything between `WM_MOUSEFIRST` and `WM_MOUSELAST` would go to the hook. – Jonathan Potter Jul 15 '19 at 23:59
  • 2
    @JonathanPotter "*I've never even worked out what an 'X' button is*" - see [XBUTTONs](https://learn.microsoft.com/en-us/windows/win32/inputdev/about-mouse-input#xbuttons) on MSDN – Remy Lebeau Jul 16 '19 at 01:07

1 Answers1

2

Are those messages also passed in the WPARAM parameter?

Yes.

For example, if you want to handle the X button messages, they are posted to your application using WM_XBUTTONDOWN and WM_XBUTTONUP. The low-order word of wParam indicates which X button is down (if any).

In addition, please refer Responding to Mouse Clicks

The WM_XBUTTONDOWN and WM_XBUTTONUP window messages apply to both XBUTTON1 and XBUTTON2. The wParam parameter indicates which button was clicked.

UINT button = GET_XBUTTON_WPARAM(wParam);  
if (button == XBUTTON1)
{
    // XBUTTON1 was clicked.
}
else if (button == XBUTTON2)
{
    // XBUTTON2 was clicked.
}
Strive Sun
  • 5,988
  • 1
  • 9
  • 26
  • @thebear8 hi, please tell me if my answer can help you. If you have any questions, please let me know at any time. – Strive Sun Aug 12 '19 at 02:29
  • Sorry, I completely forgot to accept your answer, it's quite a while ago, but I just noticed. – thebear8 May 30 '20 at 15:10