如何在vc ++ 6.0中的对话框中设置背景图像

时间:2009-09-15 19:11:12

标签: image dialog background

如何在vc ++ 6.0的对话框中设置背景图像

2 个答案:

答案 0 :(得分:2)

对于MFC,您重载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;
}

答案 1 :(得分:-1)

使用SetBackgroundImage()中的OnInitDialog()功能。 示例:

this->SetBackgroundImage(IDB_BITMAP1, BACKGR_TOPLEFT, TRUE);

有关详细信息,请参阅https://msdn.microsoft.com/en-us/library/bb983866.aspx