[英]get weird cursor position
好的,所以今天我正在使用向量yaya!
即時消息還與getcursorpos()
一起使用,我得到了奇怪的結果。
這是代碼:
VOID fRegularShot(HDC hdc, HWND hWnd)
{
Graphics graphics(hdc);
Image shot(L"RegularShots.png");
long index=0;
while(index<=(long)pRegularShots.size())
{
index+=2;
int x=pRegularShots.at(index);
int y1=index+1;
int y=pRegularShots.at(y1);
graphics.DrawImage(&shot, x, y);
}
}
///////////////////////////////////////////////////
event
case WM_LBUTTONDOWN:
iRegularShots=0;
POINT pt;
GetCursorPos(&pt);
pRegularShots.insert(pRegularShots.begin()+1, pt.y);
pRegularShots.insert(pRegularShots.begin()+1, pt.x);
InvalidateRect(hWnd, rect, false);
break;
好吧,基本上,函數fregularshots()
被調用並使用包含光標位置的矢量元素,而不是在光標位置繪制圖像。
但它似乎並未將其繪制在光標位置上。
有任何想法嗎?
GetCursorPos返回屏幕坐標中的光標位置。 使用ScreenToClient(hWnd,...)將其轉換為窗口客戶端坐標。
GetCursorPos(&pt); ScreenToClient(hWnd, &pt);
您也可以不使用GetCursorPos函數。 收到WM_LBUTTONDOWN通知時,lParam包含窗口客戶端鼠標坐標:x在低位字中,y在高位字中:
xPos = GET_X_LPARAM(lParam); yPos = GET_Y_LPARAM(lParam);
編輯:讓我們使此代碼更簡單。
vector<POINT> pRegularShots; VOID fRegularShot(HDC hdc, HWND hWnd) { Graphics graphics(hdc); Image shot(L"RegularShots.png"); long index=0; while(index < (long)pRegularShots.size()) { graphics.DrawImage(&shot, pRegularShots[index].x, pRegularShots[index].y); ++index; } } case WM_LBUTTONDOWN: POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); pRegularShots.push_back(pt); InvalidateRect(hWnd, rect, false); break;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.