BitBlt函数的用法

 在用双缓冲buffer的情况下加载大的图片时,防止有一个从上到下的刷的过程。

1.在CDialog.h中添加:

 CDC *pDC; CDC BackDC; CBitmap BackBmp; CBitmap *pOldBackBmp;

2.在OnInitDialog()函数中:

pDC=new CClientDC(this); BackDC.CreateCompatibleDC(pDC); BackBmp.CreateCompatibleBitmap(pDC,800,450); pOldBackBmp=BackDC.SelectObject(&BackBmp); CBitmap SkinBmp,*pOldSkinBmp; CDC SkinDC; SkinDC.CreateCompatibleDC(pDC); SkinBmp.LoadBitmap(RJHD_BACK); pOldSkinBmp=SkinDC.SelectObject(&SkinBmp); BackDC.BitBlt(0,0,800,450,&SkinDC,0,0,SRCCOPY); SkinDC.SelectObject(pOldSkinBmp); SkinDC.DeleteDC(); SkinBmp.DeleteObject();

3.在OnPaint()函数中从备份DC拷贝到屏的DC里实现图片的显示:

pDC->BitBlt(0,0,800,454,&BackDC,0,0,SRCCOPY);

4.在OnDestroy()函数里面回收内存,防止内存泄露。

BackDC.SelectObject(pOldBackBmp); BackBmp.DeleteObject(); BackDC.DeleteDC(); if(pDC!=NULL) { delete pDC; pDC=NULL; }

你可能感兴趣的:(BitBlt函数的用法)