MFC 画图CDC双缓冲

void CPCBGUIView::OnDraw(CDC* pDC)
{
 //CPCBGUIDoc* pDoc = GetDocument();
 //ASSERT_VALID(pDoc);
 //if (!pDoc)
 // return;

 CDC m_pMemDC;
 CBitmap m_pBitmap;

 CRect rect;
 GetClientRect(rect);

 int x=rect.Width();
 int y=rect.Height();

 m_pMemDC.CreateCompatibleDC(pDC);
 m_pBitmap.CreateCompatibleBitmap(pDC,x,y);
 m_pMemDC.SelectObject(m_pBitmap);

 pDC->SetMapMode(MM_ANISOTROPIC);//自定义方式 x向右增加 y向上增加
 pDC->SetWindowExt(x,y);
 pDC->SetViewportExt(x,-y);
 pDC->SetWindowOrg(0,y);

 m_pMemDC.SetMapMode(MM_ANISOTROPIC);
 m_pMemDC.SetWindowExt(x,y);
 m_pMemDC.SetViewportExt(x,-y);
 m_pMemDC.SetWindowOrg(0,y);

 m_pMemDC.FillSolidRect(0,0,x,y,RGB(255,255,255));//清屏
 
 CPCBDrawer::GetPCBDrawer()->Draw(pDC, &m_pMemDC,rect);//画图

 pDC->BitBlt(0,0,x,y, &m_pMemDC,0,0,SRCCOPY);//贴图

 m_pBitmap.DeleteObject();
 m_pMemDC.DeleteDC();

}

posted @ 2012-06-01 13:35  海乐学习  阅读(2951)  评论(0编辑  收藏  举报