您的位置:首页 > 其它

MFC 为对话框添加背景图片并以图片大小显示

2013-07-18 17:19 253 查看
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);//让显示区域矩形宽高和对话框大小一致,先目的后源!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: