MFC位圖的顯示分爲4步:
1)創建位圖,可以用CBitmap構造位圖對象;
2)創建兼容DC,可以用CreateCompatibleDC;
3)將位圖設置到兼容DC;
4)將該兼容DC顯示到當前DC;
void DrawBitmap(int iBitmapID)
{
CBitmap bitmap;
bitmap.LoadBitmap(iBitmapID);
BITMAP bmp;
bitmap.GetBitmap(&bmp);
CDC dcCompatible;
CDC *pDC = GetDC();
dcCompatible.CreateCompatibleDC(&pDC);
dcCompatible.SelectObject(&bitmap);
CRect rect;
GetClientRect(&rect);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
}