VC双缓冲画图实例

void CTest::OnPaint()



{



     CPaintDC dc(this); // device context for painting



     // TODO: Add your message handler code here



     // Do not call CWnd::OnPaint() for painting messages



     CPoint ptCenter;



     CRect rect,ellipseRect;



     GetClientRect(&rect);



     ptCenter = rect.CenterPoint();



     //用于缓冲作图的内存DC



     CDC dcMem; 



     //内存中承载临时图象的位图



     CBitmap bmp;



     //依附窗口DC创建兼容内存DC



     dcMem.CreateCompatibleDC(&dc);



     //创建兼容位图



     bmp.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());



     //将位图选择进内存DC



     dcMem.SelectObject(&bmp); 



     //按原来背景填充客户区,不然会是黑色



     dcMem.FillSolidRect(rect,dc.GetBkColor());



     //在内存DC上做同样的同心圆图象



     for(int i=20;i>0;i--) 



     {



         ellipseRect.SetRect(ptCenter,ptCenter);



         ellipseRect.InflateRect(i*10,i*10);



         dcMem.Ellipse(ellipseRect);



     }



     //将内存DC上的图象拷贝到前台



     dc.BitBlt(0,0,rect.Width(),rect.Height(), &dcMem,0,0,SRCCOPY);



     //删除DC



     dcMem.DeleteDC();



     //删除位图



     bmp.DeleteObject();



}

你可能感兴趣的:(实例)