MFC解决闪屏的问题

void CSepTimeView::OnDraw(CDC* pDC)
{
 CDocument* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 // TODO: add draw code here

 CRect rect;
 GetClientRect(&rect);
 CDC MemDC;
 CBitmap MemBitmap;
 MemDC.CreateCompatibleDC (NULL);
 MemBitmap.CreateCompatibleBitmap(pDC, rect.Width (), rect.Height ());
 CBitmap* pOldBit = MemDC.SelectObject (&MemBitmap);
 MemDC.FillSolidRect (0, 0, rect.Width (),rect.Height (), RGB(0, 0, 0));
 CBrush pBrush(RGB(0,0,0));
 MemDC.FillRect(CRect(0,0,rect.Width(), rect.Height()),&pBrush);     
 CBrush *pOldBrush=MemDC.SelectObject(&pBrush);

 ///
 加入需要的代码
 ///

 pDC->BitBlt (0, 0, rect.Width (), rect.Height (), &MemDC, 0, 0, SRCCOPY);
 MemBitmap.DeleteObject ();
 MemDC.DeleteDC ();


}


 

原文地址:https://www.cnblogs.com/aimenfeifei/p/3281845.html