How do you get the location, in x-y coordinate pixels, of a mouse click?
14,143
Solution 1
Assuming the plain Win32 API, use this in your handler for WM_LBUTTONDOWN
:
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
Solution 2
Visual C++:
System::Windows::Forms::Control::MousePosition
System::Windows::Forms::Cursor:: Position
C++:
Solution 3
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
bool find(xPos,yPos);
Now you will get the x and y position of the mouse pointer in the coordinate. xPos and yPos should be long:
bool find(long x,long y);
Inside, check if xPos and yPos come under any object in the screen coordinate.
Solution 4
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.
Author by
Mark
Updated on June 21, 2022Comments
-
Mark almost 2 years
In C++ (WIN32), how can I get the (X,y) coordinate of a mouse click on the screen?