0

我正在尝试创建一个在鼠标单击时将三角形/各种多边形绘制到窗口的程序。我将应用程序绘制到窗口,但是当窗口无效时我无法让它们重新绘制。

我刚刚尝试包含代码的重要部分。

当用户移动鼠标时,临时三角形将变大/变小。当他们松开鼠标左键时,三角形存储在结构中。这部分似乎工作正常,并且存储了每个三角形的信息。请记住,我目前没有在结构中使用厚度或颜色。

typedef struct
{

POINT pt[3];
unsigned int colour1;
unsigned int colour2;
unsigned int colour3;
unsigned int thickness;
unsigned int printOrder;

}Triangles;

Triangles temp_tri;
Triangles triangle_store[MAX_OBJECTS];
int triCount = 0;

case WM_LBUTTONDOWN:

if(triButtonPressed) //Faulty Feature
    {
        mouse_down_x = LOWORD(lParam);
        mouse_down_y = HIWORD(lParam);

        temp_tri.pt[0].x = mouse_down_x;
        temp_tri.pt[0].y = mouse_down_y;

        mouse_down = true;

    }

case WM_MOUSEMOVE:
if(triButtonPressed)
    {
        if(mouse_down)
        {
            temp_tri.pt[1].x= LOWORD(lParam);
            temp_tri.pt[1].y = HIWORD(lParam);
            temp_tri.pt[2].x= LOWORD(lParam) *2;
            temp_tri.pt[2].y= HIWORD(lParam) *2;

            InvalidateRect(hWnd,NULL,true);
        }
    }

case WM_LBUTTONUP:
else if(triButtonPressed)
    {
        temp_tri.pt[1].x = LOWORD(lParam);
        temp_tri.pt[1].y = HIWORD(lParam);
        temp_tri.pt[2].x= LOWORD(lParam) + 90;
        temp_tri.pt[2].y = HIWORD(lParam) + 90;
        printOrder++;
        temp_tri.printOrder = printOrder;
        triangle_store[triCount] = temp_tri;
        triCount ++;
        mouse_down = false;
    }

case WM_PAINT:

for(int  i =0; i<triCount; i++)
        {

            if(o == triangle_store[i].printOrder)
            {

                rePaintTriangles(backDC);
            }
        }

if(triButtonPressed)
    {
        if(mouse_down)
        {
            triangle(backDC);
        }
    }


void triangle(HDC hdc)
{

POINT pt[3];

pt[0].x = temp_tri.pt[0].x;
pt[0].y = temp_tri.pt[0].y; //Works fine. 
pt[1].x = temp_tri.pt[1].x;
pt[1].y = temp_tri.pt[1].y;
pt[2].x = temp_tri.pt[2].x;
pt[2].y = temp_tri.pt[2].y;

Polygon(hdc,pt,3);
}

void rePaintTriangles(HDC hdc)
{


Polygon(hdc,triangle_store[triCount].pt,3); //Doesn't Work

}
4

1 回答 1

0

当您收到 WM_PAINT 消息时,您应该调用BeginPaint以获取您应该在其中进行绘画的 HDC。

于 2012-12-19T22:50:30.257 回答