I have created a hook for mouse. I wanted to get mouse click coordinates, but the GET_X_LPARAM() gives me negative value (and always the same when clicking on different places). My problem becomes solved with GetCursorPos(), but I wonder why it is not working with GET_X_LPARAM/GET_Y_LPARAM. Here's the code:
LRESULT CALLBACK Recorder::mouseHook( int code, WPARAM wParam, LPARAM lParam ) {
if( code < 0 )
return CallNextHookEx( m_mouseHook, code, wParam, lParam );
switch( wParam ) {
case WM_LBUTTONDOWN:{
int _hereIsANegativeNumber = GET_X_LPARAM( lParam );
break;}
}
return CallNextHookEx( 0, code, wParam, lParam );
}
This is how I set the hook:
m_mouseHook = SetWindowsHookEx( WH_MOUSE_LL, &mouseHook, GetModuleHandle( NULL ), 0 );
In a WH_MOUSE_LL
hook, lParam
is not the mouse coordinates - instead it is a pointer to a MSLLHOOKSTRUCT
.
So, to get coordinates:
POINT pt = reinterpret_cast<MSLLHOOKSTRUCT*>(lParam)->pt;
See LowLevelMouseProc for more details.
Because for the WH_MOUSE_LL in the LowLevelMouseProc procedure what you get as the LPARAM variable is a pointer to a MSLLHOOKSTRUCT structure and use the pt member of it for getting the mouse coordinates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With