Both methods MFC add background images

Disclaimer: All https://blog.csdn.net/weixin_41752475/article/details/89222845 owned by rookie

The first way
to add Picture Control dialog box controls (first note add, or else to add other controls, run-time is blocked)
Picture Control Control
PIcture Control Control
setting control properties:
Here Insert Picture Description
Note, first add a Bitmap
Resources attempt, first box widening a little, the other controls set up, again and again up to the Picture control control

The second method

void *****Dlg::OnPaint()
{
	*******
	else
	{
	    //CDialogEx::OnPaint();********************此处要注释掉
		CPaintDC   dc(this);
		CRect   rect;
		GetClientRect(&rect);    //获取对话框长宽      
		CDC   dcBmp;             //定义并创建一个内存设备环境
		dcBmp.CreateCompatibleDC(&dc);             //创建兼容性DC
		CBitmap   bmpBackground;
		bmpBackground.LoadBitmap(IDB_BITMAP1);    //载入资源中图片
		BITMAP   m_bitmap;                         //图片变量               
		bmpBackground.GetBitmap(&m_bitmap);       //将图片载入位图中
		//将位图选入临时内存设备环境
		CBitmap  *pbmpOld = dcBmp.SelectObject(&bmpBackground);
		//调用函数显示图片StretchBlt显示形状可变
		dc.SetStretchBltMode(HALFTONE);             //***********添加于此,背景失真
		dc.StretchBlt(0, 0, rect.Width(), rect.Height(), &dcBmp, 0, 0, m_bitmap.bmWidth, m_bitmap.bmHeight, SRCCOPY);
	}
}

Guess you like

Origin blog.csdn.net/weixin_41752475/article/details/89222845