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. How to place a Bitmap in the center of a Cdocument document on startup

How to place a Bitmap in the center of a Cdocument document on startup

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicstutorialquestion
7 Posts 2 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.
  • L Offline
    L Offline
    Larry Mills Sr
    wrote on last edited by
    #1

    How to place a Bitmap in the center of a Cdocument document on startup? If tried to find it in codeproject and MSDN but neither shows what I want. I want to place the Bitmap in the center of the document when the program loads(opens). could someone show me code for doing this in MFC? Please. Thanks in advance. The ID of the Bitmap is IDB_FRACTK. A C++ programming language novice, but striving to learn

    C 1 Reply Last reply
    0
    • L Larry Mills Sr

      How to place a Bitmap in the center of a Cdocument document on startup? If tried to find it in codeproject and MSDN but neither shows what I want. I want to place the Bitmap in the center of the document when the program loads(opens). could someone show me code for doing this in MFC? Please. Thanks in advance. The ID of the Bitmap is IDB_FRACTK. A C++ programming language novice, but striving to learn

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Look around for a "splash screen" (here or using google...), is that what you mean?

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

      L 1 Reply Last reply
      0
      • C Code o mat

        Look around for a "splash screen" (here or using google...), is that what you mean?

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

        L Offline
        L Offline
        Larry Mills Sr
        wrote on last edited by
        #3

        No this is NOT what I'm looking for. I once saw an article that displayed a Bitmap in the CDocument/View interface, but I've lost it somehow. I'll keep hoping someone has one and meanwhile I'll keep looking.

        A C++ programming language novice, but striving to learn

        C 1 Reply Last reply
        0
        • L Larry Mills Sr

          No this is NOT what I'm looking for. I once saw an article that displayed a Bitmap in the CDocument/View interface, but I've lost it somehow. I'll keep hoping someone has one and meanwhile I'll keep looking.

          A C++ programming language novice, but striving to learn

          C Offline
          C Offline
          Code o mat
          wrote on last edited by
          #4

          I'm still not sure what you mean but...did you try overwriting the OnPaint method of your view class (or OnDraw maybe?) and do something like this:

          CBitmap bitmap;
          bitmap.LoadBitmap(IDB_WHATEVER);
          CDC MemDC;
          MemDC.CreateCompatibleDC(&dc_of_view);
          CBitmap *originalBitmap = MemDC.SelectObject(&bitmap);
          BITMAP bitmapInfo;
          bitmap.GetBitmap(&bitmapInfo);
          CRect Rect;
          GetClientRect(&Rect)
          dc.BitBlt(Rect.CenterPoint().x - bitmapInfo.bmWidth / 2,
          Rect.CenterPoint().y - bitmapInfo.bmHeight / 2,
          bitmapInfo.bmWidth,
          bitmapInfo.bmHeight,
          &MemDC,
          0,
          0,
          SRCCOPY);
          MemDC.SelectObject(originalBitmap);

          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

          L 1 Reply Last reply
          0
          • C Code o mat

            I'm still not sure what you mean but...did you try overwriting the OnPaint method of your view class (or OnDraw maybe?) and do something like this:

            CBitmap bitmap;
            bitmap.LoadBitmap(IDB_WHATEVER);
            CDC MemDC;
            MemDC.CreateCompatibleDC(&dc_of_view);
            CBitmap *originalBitmap = MemDC.SelectObject(&bitmap);
            BITMAP bitmapInfo;
            bitmap.GetBitmap(&bitmapInfo);
            CRect Rect;
            GetClientRect(&Rect)
            dc.BitBlt(Rect.CenterPoint().x - bitmapInfo.bmWidth / 2,
            Rect.CenterPoint().y - bitmapInfo.bmHeight / 2,
            bitmapInfo.bmWidth,
            bitmapInfo.bmHeight,
            &MemDC,
            0,
            0,
            SRCCOPY);
            MemDC.SelectObject(originalBitmap);

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

            L Offline
            L Offline
            Larry Mills Sr
            wrote on last edited by
            #5

            Yes, that's exactly what I was looking for. Question?: everytime the bitmap gets covered what command do I use to redraw it? (UpdateWindow??)

            A C++ programming language novice, but striving to learn

            C 1 Reply Last reply
            0
            • L Larry Mills Sr

              Yes, that's exactly what I was looking for. Question?: everytime the bitmap gets covered what command do I use to redraw it? (UpdateWindow??)

              A C++ programming language novice, but striving to learn

              C Offline
              C Offline
              Code o mat
              wrote on last edited by
              #6

              Once again i am not sure what exactly do you mean but to trigger redrawing of your view you can either use RedrawWindow[^] or InvalidateRect[^] (maybe in conjunction with UpdateWindow right after).

              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

              L 1 Reply Last reply
              0
              • C Code o mat

                Once again i am not sure what exactly do you mean but to trigger redrawing of your view you can either use RedrawWindow[^] or InvalidateRect[^] (maybe in conjunction with UpdateWindow right after).

                > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                L Offline
                L Offline
                Larry Mills Sr
                wrote on last edited by
                #7

                Thanks again.

                A C++ programming language novice, but striving to learn

                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