void CEREditorView::OnDraw(CDC* pDC)
{
CEREditorDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

if (first_time)
{
InitDB(pDC);
first_time=FALSE;
} CRect clientRect;
GetClientRect(&clientRect);
MemDC.FillSolidRect(&clientRect,RGB(255,255,255));
CBrush* mybrush=new CBrush(GetDocument()->color_self);
CPen* pPen = new CPen(PS_SOLID,1,RGB(153,0,51));
pUpdateTool->Update(&MemDC,mybrush,pPen,nFontHeight,nFontWidth,nCurrentFont, pCommandTool->getViewOption());
delete mybrush;
delete pPen;
pDC->BitBlt(0,0,clientRect.Width(),clientRect.Height(),&MemDC,0,0,SRCCOPY);
}        void CEREditorView::InitDB(CDC *pdc)
{
CRect rect(0,0,2000,2000);
// GetClientRect(&rect);
if(!MemDC.CreateCompatibleDC(NULL))
{
::PostQuitMessage(0);
}
MemBitmap.CreateCompatibleBitmap(pdc, rect.Width(), rect.Height());
MemDC.SelectObject(MemBitmap);
}我这么使用的双缓存,不过还有点儿闪.以前解决过,不过现在给忘了!网上搜了一下,说是要添加以下代码:BOOL CEREditorView::OnEraseBkgnd(CDC* pDC) 
{
// TODO: Add your message handler code here and/or call default
return FALSE;
return CScrollView::OnEraseBkgnd(pDC);
}
问题是,我加了以后还是有些闪烁!请高手指点一下,在此谢过了!!

解决方案 »

  1.   

    你的pUpdateTool->Update究竟做了哪些工作?
    是否做了很耗时的工作?另外,还有可以优化的地方象CBrush,CPen这些对象可以在InitDB中创建好,不用每次都创建又销毁。
      

  2.   

    你这里有个问题。你的双缓存处理放在OnDraw中,就不合适,OnDraw本来就是要刷新才会调用的。你把双缓存处理独立成为一个函数,在OnDraw中调用。另外,在你需要刷新屏幕时,不要调用Invalidate等函数来触发OnDraw重绘,而是直接调用你的双缓存处理函数进行重绘,这样就不会闪烁了。
      

  3.   

    还有一个问题可能搞错了,在OnEraseBkgnd里面应该返回TRUE而不是FALSE,这样才能阻止重绘背景