简体   繁体   English

如何获得鼠标点击的xy坐标像素位置?

[英]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_MOUSEMOVEWM_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.

相关问题 如何使用Win32 C ++在DirectX对象上获取鼠标单击的x,y坐标? - How to get the x,y coordinate of a mouse-click with win32 C++ on a directx object? 光电鼠标和xy坐标 - Optical mouse and x-y coordinates 我如何使用SendInput在x,y坐标上模拟双击鼠标(i khow handle)? - How i can simulate a double mouse click on window ( i khow handle) on x, y coordinate, using SendInput? 如何通过鼠标单击获得相对的x和y位置 - how to get relative x and y position from mouse click 如何检查xy轴上的碰撞 - How to check collisions on x-y axis 如何获得亮或暗像素的坐标? OpenCV的 - How to get the coordinate of bright or dark pixels? OpenCV 如何将 x 和 y 坐标的结果组织为 ASCII XY 图? - how to organize the result of x and y coordinates as an ASCII X-Y plot? 在Windows环境中,如何获取鼠标单击的坐标(相对于窗口) - How do you get the coordinates (with respect to a window) of a mouse click, in a Windows environment 获取特定 x,y 坐标处像素的颜色,然后执行单击 - Getting the color of a pixel at a specific x,y coordinate, then executing a click 如何获得cv :: keypoint的x&y坐标和大小? 我不断遇到段错误 - How do you get x&y coordinates and size of a cv::keypoint? I keep getting a segfault
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM