vc对话框添加图片背景

方法一:

 void About::OnPaint()
{
 CPaintDC dc(this); // device context for painting
 
 // TODO: Add your message handler code here
     CPaintDC   dcc(this);  
          CRect   rect;  
          GetClientRect(&rect);  
          CDC   dcMem;  
          dcMem.CreateCompatibleDC(&dc);  
          CBitmap   bmpBackground;  
          bmpBackground.LoadBitmap(IDB_BITMAP1);  
                  //IDB_BITMAP是你自己的图对应的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);  
 // Do not call CDialog::OnPaint() for painting messages
}

方法二:

响应OnEraseBkgnd消息,然后在这个消息函数里面显示图片!

BOOL CxxDlg::OnEraseBkgnd(CDC* pDC)
{
 BITMAP bm;
 m_bmp.GetBitmap(&bm);
 m_pbmCurrent = &m_bmp;
 CDC dcMem;
 dcMem.CreateCompatibleDC(pDC);
 CBitmap* pOldBitmap = dcMem.SelectObject(m_pbmCurrent);
 pDC->BitBlt(0,0,bm.bmWidth,bm.bmHeight,&dcMem,0,0,SRCCOPY);
 dcMem.SelectObject(pOldBitmap);
}

你可能感兴趣的:(vc对话框添加图片背景)