在没有DLL的情况下全局使用WH_MOUSE [英] Use WH_MOUSE globally without DLL
问题描述
我有一个代码,可以在鼠标移动时显示部分屏幕.但是WH_MOUSE不起作用.我需要将 GetModuleHandle(0),0
更改为 hInst,GetCurrentThreadId()
.
I have a code to display a part of screen when mouse moves. But the WH_MOUSE doesn't work. I need to change GetModuleHandle(0), 0
to hInst, GetCurrentThreadId()
.
但是只有当鼠标悬停在应用程序本身上时,该应用程序才能工作.
But then the application will work only when the mouse is over the application itself.
我希望它是全局的,我尝试了WH_MOUSE_LL,它比WH_MOUSE慢.
I want it global and I tried WH_MOUSE_LL, it is slower then WH_MOUSE.
是否可以在没有DLL的情况下全局使用WH_MOUSE?
Is that possible to use WH_MOUSE globally without DLL?
void SetHook()
{
gMouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, GetModuleHandle(0), 0);
}
//================================================================================
// Mouse Hook
static LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0) {
return CallNextHookEx(gMouseHook, nCode, wParam, lParam);
}
if (wParam == WM_MOUSEMOVE) {
MOUSEHOOKSTRUCT *mouseInfo = (MOUSEHOOKSTRUCT*)lParam;
int x = mouseInfo->pt.x;
int y = mouseInfo->pt.y;
PrintScreen(x, y);
}
return CallNextHookEx(gMouseHook, nCode, wParam, lParam);
}
推荐答案
是否可以在没有DLL的情况下全局使用WH_MOUSE?
Is that possible to use WH_MOUSE globally without DLL?
否,该挂钩过程必须在DLL中,以便可以将其注入到其他进程中.
No, the hook procedure needs to be in a DLL so that it can be injected into other processes.
我尝试了WH_MOUSE_LL,它比WH_MOUSE慢.
I tried WH_MOUSE_LL, it is slower then WH_MOUSE.
这可能意味着您的挂接过程很慢.
That probably means your hook procedure is slow.
这篇关于在没有DLL的情况下全局使用WH_MOUSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!