[英]How do you get the location, in x-y coordinate pixels, of a mouse click?
在C ++(WIN32)中,如何在屏幕上单击鼠标(X,y)?
Assuming the plain Win32 API, use this in your handler for WM_LBUTTONDOWN
: 假设使用普通的Win32 API,请在
WM_LBUTTONDOWN
的处理程序中使用它:
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
You can call GetMouseMovePointsEx to get the mouse position and history. 您可以调用GetMouseMovePointsEx来获取鼠标位置和历史记录。 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.
或者,如果您有权访问wndproc,则只需检查WM_MOUSEMOVE , WM_LBUTTONDOWN的lparam或x,y坐标的类似消息。
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. 现在,您将获得坐标中鼠标指针的x和y位置。 xPos and yPos should be long:
xPos和yPos应该很长:
bool find(long x,long y);
Inside, check if xPos and yPos come under any object in the screen coordinate. 在里面,检查xPos和yPos是否位于屏幕坐标中的任何对象下。
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.