低级鼠标钩-鼠标在断点处冻结 [英] Low level mouse hook - mouse freeze on breakpoint

查看:121
本文介绍了低级鼠标钩-鼠标在断点处冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自己绘制和移动窗户(使用铬嵌入式框架).为此,当鼠标移动到窗口外部时,我需要一个全局回调-因此我安装了一个低级鼠标钩子:

I would like to draw and move my windows by myself (using chromium embedded framework). To do this, i need a global callback when the mouse is being moved, outside of my window - so i installed a low level mouse hook:

hMouseLLHook = SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)mouseHookProc, hInstance, NULL);

该钩子简单地捕获鼠标事件并调用"CallNextHookEx".没问题,一切都按预期进行.我现在的问题是:如果调试器中断或引发异常,我将无法再移动鼠标..

The hook simple grabs the mouse events and calls "CallNextHookEx". No problems here, everything works as excpected. My problem now: if the debugger breaks or an exception is being thrown, I can't move the mouse anymore..

我尝试在另一个线程中处理该钩子,如下所示:

I tried processing the hook in another thread, like so:

HANDLE mouseProcHandle = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)mouseProcessor, NULL, NULL, &dwMouseProcThread);

DWORD WINAPI Win32Application::mouseProcessor(LPVOID lpParm) {
    hMouseLLHook = SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)mouseHookProc, ((Win32Application*)Application::getInstance())->hInstance, NULL);

    MSG message;
    while (GetMessage(&message, NULL, 0, 0)) {
        TranslateMessage(&message);
        DispatchMessage(&message);
    }

    UnhookWindowsHookEx(hMouseLLHook);
    return 0;
}

但这也不能解决问题.是否有解决方法,解决方案或其他方法来执行此操作?另外,我认为可能不需要低级钩子,因为我只需要了解移动情况,如果我是行中的最后一个就不会有问题,因此系统/其他进程可以处理首先是鼠标回调.

But this also does not solve the problem. Is there a workaround, solution or another method to do this? Also, I think a low level hook may not be necessary, as I only need to be informed about the moevement and it wouldn't be a problem if I would be the last one in line, so the system/other processes can process the mouse callbacks first.

推荐答案

当调试器停止整个程序(程序的所有线程)时,
如果使用钩子,可能没有解决方法.
不太准确,但是您可以改为在线程中轮询GetCursorPos.

As your debugger stop the whole program (all threads of it)
there is probably no workaround if using the hook.
Not as accurate, but you could poll GetCursorPos in a thread instead.

这篇关于低级鼠标钩-鼠标在断点处冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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