MFC: 我讀這個代碼是繪製一個橢圓(不是固體內部),但我不明白爲什麼在這裏需要兩次函數「pDC-> Ellipse(...)」? (溶膠== 0,和do_what == DRAW_ELLIPSE)爲什麼函數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->省略號(...),該橢圓將黑色固體內部。 如果我將第二個調用刪除到pDC-> Ellipse(...),則橢圓將永遠不會繪製,但在鼠標左鍵啓動時會消失。
對話框: 當移動鼠標: 鼠標移動(筆爲綠色)
當鼠標按鈕彈起: 鼠標按鈕彈出(筆爲綠色)
此外, CBrush的顏色是 「CBrush brush; pDC-> Ellipse(start.x,assist.y,end.x,end.y);」
...
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;
}
...
請縮進代碼,它很難閱讀。 – unwind