MFC:我读到这段代码是为了绘制一个椭圆(不是实心内部),但我不明白为什么这里需要两次函数“pDC->Ellipse(...)”?(溶胶 == 0,do_what==DRAW_ELLIPSE)
void CMy078207017Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
flag = 0;
end = point;
assist = point;
if(p != NULL)
{
CDC* pDC = GetDC();
CPen pen;
CBrush brush;
getpen(pen, pDC, col, bol);
if(do_what >= DRAW_LINE && do_what <= DRAW_RRECT)
{
p->p[0] = start;
p->p[1] = end;
}
if(sol == 1)
{
getbrush(brush, pDC, col);
}
if(do_what == DRAW_LINE)
{
pDC->MoveTo(start);
pDC->LineTo(end);
}
else
{
if(do_what == DRAW_ELLIPSE || do_what == DRAW_CIRCLE)
{
assist = start;
if(do_what == DRAW_CIRCLE)
{
assist.y = end.y - end.x + start.x;
}
pDC->SetROP2(R2_NOT);
pDC->Ellipse(start.x, assist.y, end.x, end.y);
pDC->SetROP2(R2_COPYPEN);
if(sol == 0)
{
pDC->SelectStockObject(NULL_BRUSH);
}
pDC->Ellipse(start.x, assist.y, end.x, end.y);
end = point;
}
}
ReleaseDC(pDC);
}
CDialog::OnLButtonUp(nFlags, point);
}
如果我删除对 pDC->Ellipse(...) 的第一次调用,椭圆内部将是黑色实心。如果我删除对 pDC->Ellipse(...) 的第二次调用,椭圆将永远不会被绘制,但会在鼠标左键向上时消失。
对话框:移动鼠标时: 鼠标移动(笔为绿色)
鼠标按钮弹出时: 鼠标按钮弹出(笔为绿色)
另外,如果我使用“CBrush画笔;pDC->Ellipse(start.x,assist.y,end.x,end.y);”,CBrush是什么颜色?
当涉及到矩形时,策略可能会更清晰:
...
else if(do_what==DRAW_RECT||do_what==DRAW_RRECT){
pDC->SetROP2(R2_NOT);
if(do_what==DRAW_RECT)
{
pDC->Rectangle(start.x,start.y,end.x,end.y);
}
else if(do_what==DRAW_RRECT)
{
pDC->RoundRect(start.x,start.y,end.x,end.y,20,20);
}
pDC->SetROP2(R2_COPYPEN);
if(sol==0)
{
pDC->SelectStockObject(NULL_BRUSH);
}
if(do_what==DRAW_RECT)
{
pDC->Rectangle(start.x,start.y,point.x,point.y);
}
else if(do_what==DRAW_RRECT)
{
pDC->RoundRect(start.x,start.y,point.x,point.y,20,20);
}
end=point;
}
...