在C ++(WIN32)中,如何在屏幕上单击鼠标(X,y)?
Assuming the plain Win32 API, use this in your handler for WM_LBUTTONDOWN
:
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
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.
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.
POINT p; //You can use this to store the values of x and y coordinates
Now assuming you will handle this on clicking the left mouse button
case WM_LBUTTONDOWN:
p.x = LOWORD(lParam); //X coordinate
p.y = HIWORD(lParam); //Y coordinate
/* the rest of your code */
break;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.