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

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

本文关键字:鼠标 函数 回调 消息      更新时间:2023-10-16

所以,我正在阅读 WinApi 文档,了解低级鼠标钩子的回调函数,我对传递给此函数的 WPARAM 参数感到困惑。

来自有关回调函数的文档:

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。

但是在有关 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 的低阶字表示哪个 X 按钮关闭(如果有的话(。

此外,请参阅响应鼠标点击

WM_XBUTTONDOWN和WM_XBUTTONUP窗口消息适用于两者 XBUTTON1和XBUTTON2。wParam 参数指示哪个按钮是 点击。

UINT button = GET_XBUTTON_WPARAM(wParam);  
if (button == XBUTTON1)
{
    // XBUTTON1 was clicked.
}
else if (button == XBUTTON2)
{
    // XBUTTON2 was clicked.
}