Reputation:
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION)
{
if (wParam == WM_MOUSEMOVE)
{
cout << "X : " << GET_X_LPARAM(lParam) << " Y: " << GET_Y_LPARAM(lParam) << "\n";
}
}
return CallNextHookEx(hMSHook, nCode, wParam, lParam);
}
int _tmain() {
HMODULE hInstance = GetModuleHandle(NULL);
hMSHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, hInstance, NULL);
MSG Msg;
while (GetMessage(&Msg, NULL, 0, 0)) { DispatchMessage(&Msg); }
::ReleaseDC(0, dc);
return 0;
}
result = Always return wrong coordinates,
example = X = -1844, Y = 79,
X = -1556 Y = 271,
X = -1028 Y = 91
...
Value is changing when every launch
somebody can help me?
Upvotes: 0
Views: 1364
Reputation: 6125
The lParam
parameter of MouseProc
is not identical to the lParam
parameter for WM_MOUSEMOVE
. It is a MOUSEHOOKSTRUCT *
.
So, change MouseProc
to :
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION)
{
auto &ms = * (const MOUSEHOOKSTRUCT *) lParam;
if (wParam == WM_MOUSEMOVE)
{
cout << "X : " << ms.pt.x << " Y: " << ms.pt.y << "\n";
}
}
return CallNextHookEx(hMSHook, nCode, wParam, lParam);
}
Upvotes: 6