how to set background image in a dialog box in vc++6.0
A:
For MFC you overload OnEraseBackground
class CMyDialog: public CDialog
{
protected:
CMyDialog::CWizardDialog(int nID);
BOOL OnEraseBkgnd(CDC* pDC);
CBitmap m_background;
};
BOOL CMyDialog::OnEraseBkgnd(CDC* pDC)
{
CDialog::OnEraseBkgnd(pDC);
if(!m_background.m_hObject)
return true;
CRect rect;
GetClientRect(&rect);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dc.SelectObject(&m_background);
BITMAP bmap;
m_background.GetBitmap(&bmap);
// stretch
pDC->StretchBlt(0, 0, rect.Width(),rect.Height(), &dc,0, 0,bmap.bmWidth,bmap.bmHeight, SRCCOPY);
// don't stretch
//pDC->StretchBlt(0, 0, rect.Width(),rect.Height(), &dc,0, 0,rect.Width(),rect.Height(), SRCCOPY);
dc.SelectObject(pOldBitmap);
return true;
}
Martin Beckett
2009-09-15 19:15:03