![](/img/trans.png)
[英]How to get the x,y coordinate of a mouse-click with win32 C++ on a directx object?
[英]How do you get the location, in x-y coordinate pixels, of a mouse click?
在C ++(WIN32)中,如何在屏幕上單擊鼠標(X,y)?
假設使用普通的Win32 API,請在WM_LBUTTONDOWN
的處理程序中使用它:
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
您可以調用GetMouseMovePointsEx來獲取鼠標位置和歷史記錄。 或者,如果您有權訪問wndproc,則只需檢查WM_MOUSEMOVE , WM_LBUTTONDOWN的lparam或x,y坐標的類似消息。
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
bool find(xPos,yPos);
現在,您將獲得坐標中鼠標指針的x和y位置。 xPos和yPos應該很長:
bool find(long x,long y);
在里面,檢查xPos和yPos是否位於屏幕坐標中的任何對象下。
POINT p; //You can use this to store the values of x and y coordinates
現在假設您將在單擊鼠標左鍵時處理此問題
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.