How do you get the location, in pixels of xy coordinates, of a mouse click?

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

+4
source share
5 answers

Assuming a simple Win32 API, use this in your handler for WM_LBUTTONDOWN :

 xPos = GET_X_LPARAM(lParam); yPos = GET_Y_LPARAM(lParam); 
+7
source

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

+1
source
 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 fall under any object in the screen coordinate.

+1
source
 POINT p; //You can use this to store the values of x and y coordinates 

Now suppose you handle this by left-clicking

  case WM_LBUTTONDOWN: px = LOWORD(lParam); //X coordinate py = HIWORD(lParam); //Y coordinate /* the rest of your code */ break; 
-one
source

All Articles