Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the location, in x-y coordinate pixels, of a mouse click?

Tags:

c++

winapi

mouse

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

like image 805
Mark Avatar asked Dec 30 '22 08:12

Mark


2 Answers

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

xPos = GET_X_LPARAM(lParam); 
yPos = GET_Y_LPARAM(lParam);
like image 138
Georg Fritzsche Avatar answered Jan 24 '23 10:01

Georg Fritzsche


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.

like image 27
Andrew Keith Avatar answered Jan 24 '23 10:01

Andrew Keith