0
我創建了一個圓形繪製的示例對話框應用程序。同樣在鼠標移動時,圓圈將被重新繪製。我在下面提供我的代碼。它也是可編譯的。MFC:閃爍問題與GDI +
我嘗試使用雙緩衝和erasebackground,我沒有得到閃爍的問題,但我觀察到,沒有正確清除drawin。所以要抹掉,在OnPaint中我寫了擦除代碼。我再次面臨閃爍的問題。
void CPOCDlg::OnPaint()
{
CPaintDC dc(this);
GetClientRect(&clientRect);
circle = clientRect;
circle.DeflateRect(100,100);
dc.SelectStockObject(NULL_BRUSH);
dc.SelectStockObject(NULL_PEN);
dc.FillSolidRect(circle, ::GetSysColor(COLOR_BTNFACE));
Bitmap buffer(circle.right, circle.bottom);
Graphics graphicsbuf(&buffer);
Graphics graphics(dc.m_hDC);
graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality);
SolidBrush brush(Color(255,71,71,71));
Pen bluePen(Color(255, 0, 0, 255),1);
graphicsbuf.DrawEllipse(&bluePen,Rect(circle.left,circle.top,circle.Width(),circle.Height()));
graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality);
graphics.DrawImage(&buffer, 0, 0);
}
void CPOCDlg::OnMouseMove(UINT nFlags, CPoint point)
{
m_point = point;
InvalidateRect(circle,FALSE);
CDialogEx::OnMouseMove(nFlags, point);
}
BOOL CPOCDlg::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
請讓我知道如果我犯了什麼錯誤。
嗨,我需要使用GDI_雙緩衝。我用它如下,但仍然是同樣的問題。你能幫忙嗎?位圖緩衝區(circle.right,circle.bottom); Graphics graphicsbuf(&buffer); 圖形圖形(dc.m_hDC); graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality); SolidBrush刷(顏色(255,71,71,71)); Pen bluePen(Color(255,0,0,055),1);圖形緩衝區.drawEllipse(&bluePen,Rect(circle.left,circle.top,circle.Width(),circle.Height())); graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality); graphics.DrawImage(&buffer,0,0); –
你應該使用原始的GDI東西進行雙緩衝,但是使用GDI +進行實際繪製 –