利用双缓冲技术;
源码:
void showBMP()
{
CString str;
CString filter="Bitmap Files(*.bmp)|*.bmp|Wmf Files(*.wmf)|*.wmf||";
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,(LPCTSTR)filter,NULL);
if (dlg.DoModal() == IDOK)
{
str=dlg.GetPathName();
HBITMAP hBitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(),str,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bitmap;
bitmap.Attach(hBitmap); //关联位图对象
CDC* pDC=GetDC();
CDC dcimage;
dcimage.CreateCompatibleDC(pDC); //内存DC
BITMAP bmp;
bitmap.GetBitmap(&bmp); //获取位图信息
dcimage.SelectObject(&bitmap); //选取位图对象
pDC->BitBlt(0,0,bmp.bmWidth,bmp.bmHeight,&dcimage,0,0,SRCCOPY); //显示
}
};