Reputation:
how to set background image in a dialog box in vc++6.0
Upvotes: 0
Views: 5704
Reputation: 51
Use the function SetBackgroundImage()
in your OnInitDialog()
.
Example:
this->SetBackgroundImage(IDB_BITMAP1, BACKGR_TOPLEFT, TRUE);
For more details, see https://msdn.microsoft.com/en-us/library/bb983866.aspx.
Upvotes: -1
Reputation: 96119
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;
}
Upvotes: 2