0

因此,我正在阅读 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 参数中传递?

4

1 回答 1

2

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

是的。

例如,如果您想处理 X 按钮消息,它们会使用WM_XBUTTONDOWN和发布到您的应用程序WM_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.
}
于 2019-07-16T06:56:54.690 回答