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. Displaying a bitmap?

Displaying a bitmap?

Scheduled Pinned Locked Moved C / C++ / MFC
questiongraphicshelptutoriallearning
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.
  • P Offline
    P Offline
    Paddy
    wrote on last edited by
    #1

    Hope some one can help me out here. What is the simplest way to display a bitmap in your client area? For example if I have created a bitmap with the resource editor eg IDB_BITMAP. How would I bitblt this to my client area? Thanks in advance, Paddy

    B 1 Reply Last reply
    0
    • P Paddy

      Hope some one can help me out here. What is the simplest way to display a bitmap in your client area? For example if I have created a bitmap with the resource editor eg IDB_BITMAP. How would I bitblt this to my client area? Thanks in advance, Paddy

      B Offline
      B Offline
      Brian Shifrin
      wrote on last edited by
      #2

      Let say you have bitmap CBitmap m_bitmap; 1) Create temporary DC 2) Select new bitmap into it 3) BitBlt from temp into controlDC OnPaint { CDC dc( this); CDC tempDC; if (tempDC.CreateCompatibleDC(&dc)) { if (m_bitmap.GetSafeHandle()) { CBitmap* pOldBM = tempDC.SelectObject(&m_bitmap); BITMAP BM; m_bitmap.GetBitmap(&BM); dc.BitBlt(0, 0, BM.bmWidth, BM.bmHeight, &tempDC, 0, 0, SRCCOPY); tempDC.SelectObject(pOldBM); } }

      P 1 Reply Last reply
      0
      • B Brian Shifrin

        Let say you have bitmap CBitmap m_bitmap; 1) Create temporary DC 2) Select new bitmap into it 3) BitBlt from temp into controlDC OnPaint { CDC dc( this); CDC tempDC; if (tempDC.CreateCompatibleDC(&dc)) { if (m_bitmap.GetSafeHandle()) { CBitmap* pOldBM = tempDC.SelectObject(&m_bitmap); BITMAP BM; m_bitmap.GetBitmap(&BM); dc.BitBlt(0, 0, BM.bmWidth, BM.bmHeight, &tempDC, 0, 0, SRCCOPY); tempDC.SelectObject(pOldBM); } }

        P Offline
        P Offline
        Paddy
        wrote on last edited by
        #3

        Thanks for the help Brian. I forgot to mention I'm not using MFC but I presume you use the same process anyway? 1) Create temporary DC 2) Select new bitmap into it 3) BitBlt from temp into controlDC Or is it different do you know? Paddy

        M 1 Reply Last reply
        0
        • P Paddy

          Thanks for the help Brian. I forgot to mention I'm not using MFC but I presume you use the same process anyway? 1) Create temporary DC 2) Select new bitmap into it 3) BitBlt from temp into controlDC Or is it different do you know? Paddy

          M Offline
          M Offline
          MAAK
          wrote on last edited by
          #4
          HDC hTempDC, hClientDC;
          HBITMAP hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1)),
          	oldBmp; //hInst is the HISTNACE of the application
          hTempDC = CreateCompatibleDC(NULL);
          oldBmp = (HBITMAP)SelectObject(hTempDC, hBmp);
          hClientDC = ::GetDC(hClientWnd); //hClientWnd is the handle of the client window
          BITMAP BM;
          GetObject(hBmp, sizeof(BITMAP), &BM);
          BitBlt(hClientDC, 0, 0, BM.bmWidth, BM.bmHeight, hTempDC, 0, 0, SRCCOPY);
          
          ReleaseDC(hClientWnd, hClientDC);
          SelectObject(hTempDC, oldBmp);
          DeleteObject(hBmp);
          DeleteDC(hTempDC);
          
          P 1 Reply Last reply
          0
          • M MAAK
            HDC hTempDC, hClientDC;
            HBITMAP hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1)),
            	oldBmp; //hInst is the HISTNACE of the application
            hTempDC = CreateCompatibleDC(NULL);
            oldBmp = (HBITMAP)SelectObject(hTempDC, hBmp);
            hClientDC = ::GetDC(hClientWnd); //hClientWnd is the handle of the client window
            BITMAP BM;
            GetObject(hBmp, sizeof(BITMAP), &BM);
            BitBlt(hClientDC, 0, 0, BM.bmWidth, BM.bmHeight, hTempDC, 0, 0, SRCCOPY);
            
            ReleaseDC(hClientWnd, hClientDC);
            SelectObject(hTempDC, oldBmp);
            DeleteObject(hBmp);
            DeleteDC(hTempDC);
            
            P Offline
            P Offline
            Paddy
            wrote on last edited by
            #5

            Excellent, thanks. Paddy.

            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