得到奇怪的光标位置

发布于 2024-09-14 16:28:52 字数 872 浏览 7 评论 0原文

好的,今天我正在使用矢量,耶耶!
嗯,我也在使用 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() 被调用并使用包含光标位置的向量元素,然后在光标位置绘制图像。
但它似乎没有将其绘制在光标位置上。
有什么想法吗?

Ok so I'm working with vectors today yaya!
well im also working with getcursorpos() and i get weird results.
here is the code:

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;

Well basically function fregularshots() get called and use the vector elements which contains the positions of the cursor than draws the image on the cursor positions.
but it doesn't seem to draw it on the cursor positions.
any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2024-09-21 16:28:52

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; 

GetCursorPos returns cursor position in screen coordinates. Use ScreenToClient(hWnd, ...) to convert it to window client coordinates.

GetCursorPos(&pt);
ScreenToClient(hWnd, &pt);

You can work also without GetCursorPos function. When WM_LBUTTONDOWN notification is received, lParam contains window client mouse coordinates: x in low-order word, y in high-order word:

xPos = GET_X_LPARAM(lParam); 
yPos = GET_Y_LPARAM(lParam); 

Edit:
Let's make this code more simple.

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; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文