How to set a bitmap as a dialog background ?
-
It goes along this:
Class CYourDlg: public CDialog{
...
CBitmap m_bitmap_background;
BITMAP m_bmInfo_background;
...
};BOOL CYourDlg::OnInitDialog()
{
...
m_bitmap_background.LoadBitmap(IDB_BACKGROUND);
::GetObject(m_bitmap_background,sizeof(BITMAP),&m_bmInfo_background);
...
return TRUE;
}BOOL CYourDlg::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(rect);CDC dcMem; dcMem.CreateCompatibleDC(pDC); HBITMAP\* pBmpOld=(HBITMAP\*)::SelectObject(dcMem.m\_hDC,m\_bitmap\_background); for(int y=rect.top;y<rect.bottom;y+=m\_bmInfo\_background.bmHeight){ for(int x=rect.left;x<=rect.right;x+=m\_bmInfo\_background.bmWidth){ pDC->BitBlt(x,y,m\_bmInfo\_background.bmWidth,m\_bmInfo\_background.bmHeight, &dcMem,0,0,SRCCOPY); } } ::SelectObject(dcMem.m\_hDC, pBmpOld); return TRUE;
}
This is for a tesellation effect (sort of like background images in HTML). Easy to adapt it to your specific needs. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
It goes along this:
Class CYourDlg: public CDialog{
...
CBitmap m_bitmap_background;
BITMAP m_bmInfo_background;
...
};BOOL CYourDlg::OnInitDialog()
{
...
m_bitmap_background.LoadBitmap(IDB_BACKGROUND);
::GetObject(m_bitmap_background,sizeof(BITMAP),&m_bmInfo_background);
...
return TRUE;
}BOOL CYourDlg::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(rect);CDC dcMem; dcMem.CreateCompatibleDC(pDC); HBITMAP\* pBmpOld=(HBITMAP\*)::SelectObject(dcMem.m\_hDC,m\_bitmap\_background); for(int y=rect.top;y<rect.bottom;y+=m\_bmInfo\_background.bmHeight){ for(int x=rect.left;x<=rect.right;x+=m\_bmInfo\_background.bmWidth){ pDC->BitBlt(x,y,m\_bmInfo\_background.bmWidth,m\_bmInfo\_background.bmHeight, &dcMem,0,0,SRCCOPY); } } ::SelectObject(dcMem.m\_hDC, pBmpOld); return TRUE;
}
This is for a tesellation effect (sort of like background images in HTML). Easy to adapt it to your specific needs. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo