2009-09-15 3 views

Répondre

2

Pour MFC vous surchargez

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; 
} 
+0

cette compilation, mais ne fonctionne pas pour moi. Je ne sais pas pourquoi –

-1

Utilisez la fonction SetBackgroundImage() dans votre OnInitDialog(). Exemple:

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

Pour plus de détails, voir https://msdn.microsoft.com/en-us/library/bb983866.aspx.

+0

Bien que ce lien puisse répondre à la question, il est préférable d'inclure les parties essentielles de la réponse ici et fournir le lien pour référence. Les réponses à lien uniquement peuvent devenir invalides si la page liée change. – NathanOliver

+0

qui sonne bien –

Questions connexes