Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GDI: Background image

GDI: Background image

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicstutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hosam Aly Mahmoud
    wrote on last edited by
    #1

    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

    H A 2 Replies Last reply
    0
    • H 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

      H Offline
      H Offline
      HPSI
      wrote on last edited by
      #2

      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.

      H 1 Reply Last reply
      0
      • H 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

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        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!

        H 1 Reply Last reply
        0
        • H HPSI

          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.

          H Offline
          H Offline
          Hosam Aly Mahmoud
          wrote on last edited by
          #4

          Thank you very much!

          Hosam Aly Mahmoud

          1 Reply Last reply
          0
          • A Anonymous

            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!

            H Offline
            H Offline
            Hosam Aly Mahmoud
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups