tags:

views:

259

answers:

3

In C++ (WIN32), how can I get the (X,y) coordinate of a mouse click on the screen?

+1  A: 

You can call GetMouseMovePointsEx to get the mouse position and history. Alternatively, if you have access to your wndproc, you can just check the lparam of WM_MOUSEMOVE, WM_LBUTTONDOWN or similar message for the x,y coordinates.

Andrew Keith
+3  A: 

Assuming the plain Win32 API, use this in your handler for WM_LBUTTONDOWN:

xPos = GET_X_LPARAM(lParam); 
yPos = GET_Y_LPARAM(lParam);
Georg Fritzsche
This is the correct answer because it tells you where the mouse *was* when the user clicked, instead of where it *is* when you process the message (it might have moved).
Greg Hewgill