为什么WM_MOUSEWHEEL在WH_GETMESSAGE挂钩中触发,而在WH_MOUSE挂钩中不触发?

时间:2020-04-29 17:48:20

标签: c++ winapi hook mousewheel

我已经设置了两个线程本地挂钩(在Explorer浏览器帮助器对象的上下文中),如下所示:

SetWindowsHookEx(   WH_MOUSE,
                    MouseHookProc,
                    NULL,
                    GetCurrentThreadId()  );

SetWindowsHookEx(   WH_GETMESSAGE,
                    GetMsgProc,
                    NULL,
                    GetCurrentThreadId()  );

我的钩子程序看起来像这样:

LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode < 0)
    {
        return CallNextHookEx(NULL, nCode, wParam, lParam);
    }

    switch (wParam)
    {

    case WM_MOUSEWHEEL:
        ATLTRACE("\n WM_MOUSEWHEEL from MouseHookProc \n"); // <-- Does not print on mouse wheel movement
        break;
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode < 0)
    {
        return CallNextHookEx(NULL, nCode, wParam, lParam);
    }

    LPMSG lpmsg = (LPMSG)lParam;
    UINT msg = LOWORD(lpmsg->message);

    switch (msg)
    {

    case WM_MOUSEWHEEL:
        ATLTRACE("\n WM_MOUSEWHEEL from GetMsgProc \n");  // <-- Prints on mouse wheel movement
        break;
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

似乎只有WH_GETMESSAGE钩会收到WM_MOUSEWHEEL消息。我是在做错什么,还是那应该发生?如果那应该发生,为什么呢?感谢您提供任何信息。

作为旁注,在调查这一点时,我发现了Windows中的一个错误(至少使用Synaptics触控板在8.1上)。如果您在资源管理器中选择一个文件,然后单击该名称以启动重命名计时器,然后在出现重命名控件之前开始滚动,则重命名控件仍将出现并在滚动后才浮动:Explorer scroll/rename bug gif < / p>

0 个答案:

没有答案