Retrieving the mouse coordinates in Windows

Started by
4 comments, last by Ximmer 19 years, 7 months ago
hi Forum, could anyone tell me how to go about retrieving the mouse coordinates in Windows? Thanks DarkStar UK
---------------------------------------------You Only Live Once - Don't be afriad to take chances.
Advertisement
Likely you'll want to trap some mouse message like say,

WM_LBUTTONDOWN in your wndproc, this will give you two things

wParam and lParam. Loosely speaking the first two bytes of lparam is the x coord and the next two are the y coord.

x = HIWORD(lParam);
y = LOWORD(lParam);

is typical.

Hope this helps.

jbc.


thanks for that. I was just wondering if there is a function that can retrieve the coordinates because where I need those coordinates are in a different location from my WindowProc() function.


Thanks

DarkStar
UK
---------------------------------------------You Only Live Once - Don't be afriad to take chances.
You want GetCursorPos().
Quote:Original post by Dark Star
thanks for that. I was just wondering if there is a function that can retrieve the coordinates because where I need those coordinates are in a different location from my WindowProc() function.


off the top of my head, not I can think of. Maybe just write something in the wndproc to respond to mouse moves (WM_MOUSEMOVE) and record the x,y pos, and write your own function to return their values.

jbc

Also if you want the mouse coordinates relative to your window you'll want ScreenToClient(...)

This topic is closed to new replies.

Advertisement