1,新建MFC工程,名为BitmapDlg后再资源视图里添加一个位图资源控件(我添加过.PNG的图)设ID为IDB_BITMAP1;
2.在BitmapDlg.Dlg里的Onpaint()里添加如下代码:
CPaintDC dc(this);
CBitmap m_bitmap;
m_bitmap.LoadBitmap(IDB_BITMAP1);//
CDC memdc;
memdc.CreateCompatibleDC(&dc);
memdc.SelectObject(&m_bitmap);
int width, height;
BITMAP bmp;
m_bitmap.GetBitmap(&bmp);
width = bmp.bmWidth;
height = bmp.bmHeight;
CRect rect;
this->GetClientRect(&rect);
dc.StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),&memdc,0,0,width,height,SRCCOPY);