dll代码:
#define _WIN32_WINNT 0x400 #include <windows.h> #pragma data_seg("Shared") HHOOK NextHook = NULL; SIZE Screen = {0, 0}; POINT pt = {0, 0}; #pragma data_seg() HMODULE Module; BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { if (ul_reason_for_call == DLL_PROCESS_ATTACH) Module = hModule; return TRUE; } LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode == 0) { PMSLLHOOKSTRUCT mhs = (PMSLLHOOKSTRUCT)lParam;
if (mhs->pt.x != pt.x || mhs->pt.y != pt.y) { pt.x = pt.x - (mhs->pt.x - pt.x); pt.y = pt.y - (mhs->pt.y - pt.y);
if (pt.x < 0) pt.x = 0; if (pt.y < 0) pt.y = 0; if (pt.x >= Screen.cx) pt.x = Screen.cx - 1; if (pt.y >= Screen.cy) pt.y = Screen.cy - 1; SetCursorPos(pt.x, pt.y); return TRUE; } } return CallNextHookEx(NextHook, nCode, wParam, lParam); } __declspec(dllexport) void StartHook() { Screen.cx = GetSystemMetrics(SM_CXSCREEN); Screen.cy = GetSystemMetrics(SM_CYSCREEN); GetCursorPos(&pt); NextHook = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMouseProc, Module, 0); } __declspec(dllexport) void StopHook() { UnhookWindowsHookEx(NextHook); } |