保存 2 次鼠标单击的坐标以及它们之间的绘图线 c++

Saving coordinates of 2 mouse clicks and the drawing line between them c++

本文关键字:之间 绘图 c++ 鼠标 单击 坐标 保存      更新时间:2023-10-16
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{        HDC hdc;
        int count=1; int xs,ys,xe,ye;
    switch (message)                 
    {
        case WM_LBUTTONDOWN
        hdc=GetDC(hwnd);
             if(count%2!=1){
             xs=GET_X_LPARAM(lParam);
             ys=GET_Y_LPARAM(lParam);}  
             else{
             xe=GET_X_LPARAM(lParam);
             ye=GET_Y_LPARAM(lParam);
             drawline(hdc,xs,ys,xe,ye);
             }
          ReleaseDC(hwnd,hdc);
          count++;
        break;
        case WM_DESTROY:
            PostQuitMessage (0);       
            break;
        default:                      
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

我已经尝试过,但是这段代码有问题。

使用

if(count%2 == 1)

而不是

if(count%2 != 1)

然后可能会工作。