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

时间:2019-07-15 23:22:43

标签: c++ winapi mouse-hook

因此,我在阅读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。

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

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参数传递?

1 个答案:

答案 0 :(得分:0)

这些消息是否也通过WPARAM参数传递?

是的

例如,如果要处理X按钮消息,它们将使用WM_XBUTTONDOWNWM_XBUTTONUP发布到您的应用程序中。 wParam的低位字表示哪个X按钮处于按下状态(如果有)。

此外,请参阅Responding to Mouse Clicks

  

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.
}