1.引入位图资源,ID为:IDB_BITMAP1
2.OnInitDialog()中添加:
CPaintDC dc(this);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP1); //IDB_BITMAP是你自己的图对应的ID
BITMAP bitmap;
bmpBackground.GetBitmap(&bitmap);
SetWindowPos(NULL,0,0,bitmap.bmWidth,bitmap.bmHeight,SWP_NOZORDER|SWP_NOMOVE);
3OnPaint()的else中改为:
// CDialog::OnPaint();
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
// GetWindowRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP1); //IDB_BITMAP1是背景位图对应的ID
BITMAP bitmap;
bmpBackground.GetBitmap(&bitmap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);//让显示区域矩形宽高和对话框大小一致,先目的后源!