1.1 MFC对话框背景设置

1.修改背景颜色

在OnPaint()函数中else后括号内添加以下代码

CRect   rect; 

                   CPaintDC   dc(this); 

                   GetClientRect(rect); 

                   dc.FillSolidRect(rect,RGB(66,132,217)); 

                   CDialogEx::OnPaint();

2.置背景图片

在OnPaint()函数中else后括号内添加以下代码

                   CRect                 rect; 

                   CPaintDC dc(this); 

                   GetClientRect(rect); 

                   //设置背景颜色

                   //dc.FillSolidRect(rect,RGB(66,132,217));

                   CDC          dcMem;

                   dcMem.CreateCompatibleDC(&dc);

                   CBitmap  bmpBackground;

                   bmpBackground.LoadBitmapA(IDB_BITMAP_BK1);

 

                   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);

                   //CDialogEx::OnPaint();//添加背景图片,需注释掉

你可能感兴趣的:(代码,mfc,背景图片,背景颜色,对话框)