使用WH_MOUSE的SetWindowsHookEx无法捕获HTCAPTION区域上的鼠标移动 [英] SetWindowsHookEx with WH_MOUSE not capturing mouse moves over HTCAPTION area

查看:234
本文介绍了使用WH_MOUSE的SetWindowsHookEx无法捕获HTCAPTION区域上的鼠标移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将SetWindowsHookEx与WH_MOUSE一起使用以捕获鼠标移动事件.它可以在除HTCAPTION区域之外的任何地方使用(至少在我的代码示例中).我找不到对此行为的任何参考,因此我尝试进入另一个执行相同操作以监视鼠标移动的应用程序.所使用的方法也是WH_MOUSE,并且即使鼠标悬停在字幕区域上,也会生成事件.因此,它应该可以工作,除非不能.

I try to use SetWindowsHookEx with WH_MOUSE to capture mouse move events. It work everywhere but over HTCAPTION areas (at least in my code sample ). I can't find any reference to this behavior and I tried to windbg into another application that do the same to monitor mouse moves. The method used is WH_MOUSE as well, and the events are generated even when the mouse is over caption areas. Hence, it should work except it doesn't.

有什么想法吗?

我正在使用它来挂钩所有进程.我建立了一个单独的dll,将消息转发到应用程序中的某些内部窗口. 我使用dwThreadId = 0. 我也没有在标题区域中单击鼠标.

Edit : I'm using this to hook in all processes. I built a separate dll that forward messages to some internal window in my application. I use dwThreadId = 0. I don't get mouse click in the caption area either.

推荐答案

我知道了:

MouseHookProc提供给SetWindowsHookEx的mouseproc接收鼠标的所有事件,这意味着我必须测试wParam等于WM_MOUSE或 WM_NCMOUSEMOVE .当光标在客户区上方时,会收到WM_MOUSE;当光标在非客户区上方时,会触发WM_NCMOUSEMOVE(就像在正常消息proc中一样).

MouseHookProc the mouseproc given to SetWindowsHookEx receive all the events of the mouse that mean I have to test that wParam is equal to WM_MOUSE or WM_NCMOUSEMOVE. When the cursor is over a client area WM_MOUSE is received and when it is over a nonclient area WM_NCMOUSEMOVE is fired (like in a normal message proc ).

LRESULT CALLBACK MouseHookProc(int nCode, WORD wParam, DWORD lParam)
{
    if(nCode>=0 && (wParam==WM_MOUSEMOVE || wParam==WM_NCMOUSEMOVE))
    {
        if(!hwnd)
            hwnd=FindWindow(0, "MyWindow");

        MSLLHOOKSTRUCT *mhs=(MSLLHOOKSTRUCT*)lParam;        
        PostMessage(hwnd, WM_MOUSEHOOK, wParam, 0);
    }
    return CallNextHookEx(hHook,nCode,wParam,lParam);
}

我认为WM_MOUSE是某种相应的值,但不是真正的鼠标消息,而是它.

I thought that WM_MOUSE was some sort of corresponding value but not the real mouse message, but it is.

这篇关于使用WH_MOUSE的SetWindowsHookEx无法捕获HTCAPTION区域上的鼠标移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆