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 +进行实际绘制 –