哪些消息可以传递给低级鼠标钩子回调函数?

Which messages can be passed to a low-level mouse hook callback function?

因此,我在阅读有关低级鼠标挂钩的回调函数的 WinApi 文档时,对传递给该函数的 WPARAM 参数感到困惑。

来自Documentation关于回调函数:

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.

这只提到了 WM_LBUTTONDOWN、WM_LBUTTONUP、WM_MOUSEMOVE、WM_MOUSEWHEEL、WM_MOUSEHWHEEL、WM_RBUTTONDOWN 和 WM_RBUTTONUP。

但是在Documentation关于MSLLHOOKSTRUCT结构(与低级鼠标钩子一起使用)中,还提到了其他消息:

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.

这些消息是否也在 WPARAM 参数中传递?

这些消息是否也在 WPARAM 参数中传递?

是的。

例如,如果您想要处理 X 按钮消息,它们将使用 WM_XBUTTONDOWNWM_XBUTTONUP 发布到您的应用程序。 wParam 的 low-order 字表示按下了哪个 X 按钮(如果有的话)。

另外,请参考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.
}