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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MainFrame Bitmap

MainFrame Bitmap

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicshelptutorial
7 Posts 4 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.
  • I Offline
    I Offline
    Igor Kondrasovas
    wrote on last edited by
    #1

    Hello, I'm working on a MDI project and I'd like to insert a bitmap in the background of my application, in other words, on my MainFrame window, behind the children windows. This bitmap will be always there. I'm workin with VC++ 6.0 and Windows 2000. If anybody know how to this, please, help me. Best Regards, Igor Kondrasovas

    M J 2 Replies Last reply
    0
    • I Igor Kondrasovas

      Hello, I'm working on a MDI project and I'd like to insert a bitmap in the background of my application, in other words, on my MainFrame window, behind the children windows. This bitmap will be always there. I'm workin with VC++ 6.0 and Windows 2000. If anybody know how to this, please, help me. Best Regards, Igor Kondrasovas

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      It's very easy use GDI+.Check this and this Mazy Don't Marry a Person You Can Live With... Marry Someone You Can Not Live Without

      1 Reply Last reply
      0
      • I Igor Kondrasovas

        Hello, I'm working on a MDI project and I'd like to insert a bitmap in the background of my application, in other words, on my MainFrame window, behind the children windows. This bitmap will be always there. I'm workin with VC++ 6.0 and Windows 2000. If anybody know how to this, please, help me. Best Regards, Igor Kondrasovas

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        It's simple task, but many steps are required:

        1. Create a new CWnd-derived class, say CBackgroundWnd.

        2. Add these two members to CBackgroundWnd:

          CBitmap m_bitmap_background;
          BITMAP m_bmInfo_background;

          along with this piece of code in CBackgroundWnd ctor:

          m\_bitmap\_background.LoadBitmap(IDB\_BACKGROUND); // change IDB\_BACKGROUND to whatever your resource-located bitmap is called.
          ::GetObject(m\_bitmap\_background,sizeof(BITMAP),&m\_bmInfo\_background);
          
        3. Add a handler for WM_ERASEBKGND in CBackgroundWnd and plug this code (which draws the bitmap in tesellation mode)

          BOOL CBackgroundWnd::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;
          

          }

        4. Add a member of type CBackgroundWnd to your CMainFrame class, say m_wndClient.

        5. Override CMainFrame::OnCreateClient with this:

          BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
          {
          if(!CMDIFrameWnd::OnCreateClient(lpcs, pContext))return FALSE;
          m_wndClient.SubclassWindow(m_hWndMDIClient);
          return TRUE;
          }

        That's it, I think. Good luck. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        C 1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          It's simple task, but many steps are required:

          1. Create a new CWnd-derived class, say CBackgroundWnd.

          2. Add these two members to CBackgroundWnd:

            CBitmap m_bitmap_background;
            BITMAP m_bmInfo_background;

            along with this piece of code in CBackgroundWnd ctor:

            m\_bitmap\_background.LoadBitmap(IDB\_BACKGROUND); // change IDB\_BACKGROUND to whatever your resource-located bitmap is called.
            ::GetObject(m\_bitmap\_background,sizeof(BITMAP),&m\_bmInfo\_background);
            
          3. Add a handler for WM_ERASEBKGND in CBackgroundWnd and plug this code (which draws the bitmap in tesellation mode)

            BOOL CBackgroundWnd::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;
            

            }

          4. Add a member of type CBackgroundWnd to your CMainFrame class, say m_wndClient.

          5. Override CMainFrame::OnCreateClient with this:

            BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
            {
            if(!CMDIFrameWnd::OnCreateClient(lpcs, pContext))return FALSE;
            m_wndClient.SubclassWindow(m_hWndMDIClient);
            return TRUE;
            }

          That's it, I think. Good luck. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Why couldn't he just erase background in the mainframe ? Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001 Picture the daffodil. And while you do that, I'll be over here going through your stuff.

          J 1 Reply Last reply
          0
          • C Christian Graus

            Why couldn't he just erase background in the mainframe ? Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001 Picture the daffodil. And while you do that, I'll be over here going through your stuff.

            J Offline
            J Offline
            Joaquin M Lopez Munoz
            wrote on last edited by
            #5

            Good question... I created a test MDI project and tried that approach first, to discover that my tesellation got overdrawn by the standard dark-grey background (I noticed because of the flickering). I remembered then about that funky, mostly unknown CMainFrame::m_hWndMDIClient member and how it seems to take on some of the roles people tend to ascribe to CMainFrame itself... got it subclassed and WM_ERASEBKGND-handled, and it worked. Couldn't say if this is the most direct approach. Any ideas? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            C 1 Reply Last reply
            0
            • J Joaquin M Lopez Munoz

              Good question... I created a test MDI project and tried that approach first, to discover that my tesellation got overdrawn by the standard dark-grey background (I noticed because of the flickering). I remembered then about that funky, mostly unknown CMainFrame::m_hWndMDIClient member and how it seems to take on some of the roles people tend to ascribe to CMainFrame itself... got it subclassed and WM_ERASEBKGND-handled, and it worked. Couldn't say if this is the most direct approach. Any ideas? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Interesting - I've only ever done this in a view, so I had no idea of this problem. Sounds like it's worth a fiddle sometime. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001 Picture the daffodil. And while you do that, I'll be over here going through your stuff.

              J 1 Reply Last reply
              0
              • C Christian Graus

                Interesting - I've only ever done this in a view, so I had no idea of this problem. Sounds like it's worth a fiddle sometime. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001 Picture the daffodil. And while you do that, I'll be over here going through your stuff.

                J Offline
                J Offline
                Joaquin M Lopez Munoz
                wrote on last edited by
                #7

                ...so I had no idea of this problem Neither did I :) Thought I'd write a test before submitting an answer, and came to this (to my surprise). Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                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