GDI: Background image
-
Could someone please tell me how to make the background of a dialog a bitmap? I am using MFC on VC++ 6.0.
Hosam Aly Mahmoud
-
Could someone please tell me how to make the background of a dialog a bitmap? I am using MFC on VC++ 6.0.
Hosam Aly Mahmoud
-
Could someone please tell me how to make the background of a dialog a bitmap? I am using MFC on VC++ 6.0.
Hosam Aly Mahmoud
like this: void CAaDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CRect rect; GetClientRect(&rect); CPaintDC dc(this); CBitmap bitmap; BITMAP Bitmap; bitmap.LoadBitmap(IDB_BITMAP1); bitmap.GetObject(sizeof(BITMAP),&Bitmap); CDC dcMem; dcMem.CreateCompatibleDC(&dc); CBitmap* poldbitmap=dcMem.SelectObject(&bitmap); dc.StretchBlt(0,0,rect.Width(),rect.Height(), &dcMem,0,0,Bitmap.bmWidth,Bitmap.bmHeight,SRCCOPY); dcMem.SelectObject(poldbitmap); dcMem.DeleteDC(); } } void CAaDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); // TODO: Add your message handler code here Invalidate(TRUE); } may be useful!
-
Take a look at this. HPS HwndSpy - GUI developer's aid to visually locate and inspect windows. For the month of August only, use coupon code CP-81239 for 30% off.
Thank you very much!
Hosam Aly Mahmoud
-
like this: void CAaDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CRect rect; GetClientRect(&rect); CPaintDC dc(this); CBitmap bitmap; BITMAP Bitmap; bitmap.LoadBitmap(IDB_BITMAP1); bitmap.GetObject(sizeof(BITMAP),&Bitmap); CDC dcMem; dcMem.CreateCompatibleDC(&dc); CBitmap* poldbitmap=dcMem.SelectObject(&bitmap); dc.StretchBlt(0,0,rect.Width(),rect.Height(), &dcMem,0,0,Bitmap.bmWidth,Bitmap.bmHeight,SRCCOPY); dcMem.SelectObject(poldbitmap); dcMem.DeleteDC(); } } void CAaDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); // TODO: Add your message handler code here Invalidate(TRUE); } may be useful!
Thank you for your reply. But shouldn't this be handled in the WM_ERASEBKGND message (or the corresponding OnEraseBkgnd function)? Which one is better? Thank you again.
Hosam Aly Mahmoud