如何获取鼠标单击的位置(以 xy 坐标像素为单位)?
在C++(WIN32)中,如何获取鼠标在屏幕上单击的(X,y)坐标?
In C++ (WIN32), how can I get the (X,y) coordinate of a mouse click on the screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
假设使用普通 Win32 API,请在 < 的处理程序中使用此 API代码>WM_LBUTTONDOWN:
Assuming the plain Win32 API, use this in your handler for
WM_LBUTTONDOWN
:您可以调用 GetMouseMovePointsEx 来获取鼠标位置和历史。或者,如果您有权访问 wndproc,则只需检查 WM_MOUSEMOVE,WM_LBUTTONDOWN 或 x,y 坐标的类似消息。
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.
Visual C++:
GetCursorPos
系统::Windows::Forms::Control::MousePosition< /a>
System::Windows::Forms ::光标::位置
C++:
鼠标位置
Visual C++:
GetCursorPos
System::Windows::Forms::Control::MousePosition
System::Windows::Forms::Cursor:: Position
C++:
Mouse Position
现在您将获得鼠标指针在坐标中的 x 和 y 位置。 xPos 和 yPos 应该很长:
在内部,检查 xPos 和 yPos 是否位于屏幕坐标中的任何对象下方。
Now you will get the x and y position of the mouse pointer in the coordinate. xPos and yPos should be long:
Inside, check if xPos and yPos come under any object in the screen coordinate.
现在假设您将通过单击鼠标左键来处理此问题
Now assuming you will handle this on clicking the left mouse button