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);
}
问题是,我加了以后还是有些闪烁!请高手指点一下,在此谢过了!!
{
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);
}
问题是,我加了以后还是有些闪烁!请高手指点一下,在此谢过了!!
是否做了很耗时的工作?另外,还有可以优化的地方象CBrush,CPen这些对象可以在InitDB中创建好,不用每次都创建又销毁。