您的位置:首页 > 其它

双缓冲绘图,防止闪烁

2010-12-05 21:53 232 查看
void CBMSView::OnDraw(CDC* pDC)
{
   CBitmap bmp;
   if (bmp.LoadBitmap(IDB_BITMAP_MAP))//绘出楼层平面图
   {
      // Get the size of the bitmap
      BITMAP bmpInfo;
      bmp.GetBitmap(&bmpInfo);   

      // Create an in-memory DC compatible with the
      // display DC we're using to paint
      CDC dcMemory;
      dcMemory.CreateCompatibleDC(pDC);

  // bmp.CreateCompatibleBitmap(&dcMemory, bmpInfo.bmWidth, bmpInfo.bmHeight); 

   // Select the bitmap into the in-memory DC
      CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);

      // Find a centerpoint for the bitmap in the client area

      CRect rect;
     GetClientRect(&rect);

      // Copy the bits from the in-memory DC into the on-
      // screen DC to actually do the painting. Use the centerpoint
      // we computed for the target offset.  
      pDC->BitBlt(rect.left ,rect.top,rect.Width(),rect.Height(), &dcMemory, 
         0, 0, SRCCOPY);
        
      dcMemory.SelectObject(pOldBitmap);
   }
   else
   {
      TRACE0("ERROR: Where's IDB_BITMAP_MAP?/n");
   }
}




注意:应用到mfc项目dcMemory,bmp应为类成员,否则闪烁严重



PS.摘自MSDN
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: