我正在尝试画一个圆圈,我目前正在使用 Ellipse() 函数。
我有起始鼠标坐标 - x1 和 y1 以及结束坐标 x2 和 y2。如您所见,我强制 y2(temp_shape.bottom) 为 = y1+(x2-x1)。这不能按预期工作。我知道计算是完全错误的,但是关于什么是正确的有什么想法吗?
代码如下。
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rect;
GetClientRect(hWnd, &rect);
HDC backbuffDC = CreateCompatibleDC(hdc);
HBITMAP backbuffer = CreateCompatibleBitmap( hdc, rect.right, rect.bottom);
int savedDC = SaveDC(backbuffDC);
SelectObject( backbuffDC, backbuffer );
HBRUSH hBrush = CreateSolidBrush(RGB(255,255,255));
FillRect(backbuffDC,&rect,hBrush);
DeleteObject(hBrush);
//Brush and Pen colours
SelectObject(backbuffDC, GetStockObject(DC_BRUSH));
SetDCBrushColor(backbuffDC, RGB(255,0,0));
SelectObject(backbuffDC, GetStockObject(DC_PEN));
SetDCPenColor(backbuffDC, RGB(0,0,0));
//Shape Coordinates
temp_shape.left=x1;
temp_shape.top=y1;
temp_shape.right=x2;
temp_shape.bottom=y2;
//Draw Old Shapes
//Rectangles
for ( int i = 0; i < current_rect_count; i++ )
{
Rectangle(backbuffDC, rect_list[i].left, rect_list[i].top, rect_list[i].right, rect_list[i].bottom);
}
//Ellipses
for ( int i = 0; i < current_ellipse_count; i++ )
{
Ellipse(backbuffDC, ellipse_list[i].left, ellipse_list[i].top, ellipse_list[i].right, ellipse_list[i].bottom);
}
if(mouse_down)
{
if(drawCircle)
{
temp_shape.right=y1+(x2-x1);
Ellipse(backbuffDC, temp_shape.left, temp_shape.top, temp_shape.right, temp_shape.bottom);
}
if(drawRect)
{
Rectangle(backbuffDC, temp_shape.left, temp_shape.top, temp_shape.right, temp_shape.bottom);
}
if(drawEllipse)
{
Ellipse(backbuffDC, temp_shape.left, temp_shape.top, temp_shape.right, temp_shape.bottom);
}
}
BitBlt(hdc,0,0,rect.right,rect.bottom,backbuffDC,0,0,SRCCOPY);
RestoreDC(backbuffDC,savedDC);
DeleteObject(backbuffer);
DeleteDC(backbuffDC);
EndPaint(hWnd, &ps);
}
break;