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. HBITMAP to picture control

HBITMAP to picture control

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++graphicsdata-structuresperformance
6 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.
  • C Offline
    C Offline
    cherrymotion
    wrote on last edited by
    #1

    Hi guys, I have a dialog box on mfc and put a picture control onto it. Now it is no problem to load images from a path of my harddisk, they are shown well. But i dont know, how to load BITMAPS dynamically into the control. First I create a new Bitmap with the CreateBitmap() function from a Byte-Array. The function returns a non-zero value, so it was successfull. But now i have somehow to copy that bitmap into a memory-hdc, and from there i should be able to load it into the control. but i dont get it!!! I added a variable to the control from the type CStatic. But why is it so complicated, to get that created HBITMAP onto the Control? I mean, there IS a CStatic-function, which lets me SetBitmap(HBITMAP hBitmap)... But it does not work!!! I hope someone can help me... Best regards, cherry :doh:

    stefanmihaimogaS M 2 Replies Last reply
    0
    • C cherrymotion

      Hi guys, I have a dialog box on mfc and put a picture control onto it. Now it is no problem to load images from a path of my harddisk, they are shown well. But i dont know, how to load BITMAPS dynamically into the control. First I create a new Bitmap with the CreateBitmap() function from a Byte-Array. The function returns a non-zero value, so it was successfull. But now i have somehow to copy that bitmap into a memory-hdc, and from there i should be able to load it into the control. but i dont get it!!! I added a variable to the control from the type CStatic. But why is it so complicated, to get that created HBITMAP onto the Control? I mean, there IS a CStatic-function, which lets me SetBitmap(HBITMAP hBitmap)... But it does not work!!! I hope someone can help me... Best regards, cherry :doh:

      stefanmihaimogaS Online
      stefanmihaimogaS Online
      stefanmihaimoga
      wrote on last edited by
      #2

      Hi, I don't think there's an easy answer to your question. I do not known what is wrong in what you did with the code. But, did you had a look into these articles? 1) Chris Maunder's DIBSection wrapper[^] 2) Chris Maunder's auto-sizing bitmap control[^] 3) Troels Knakkergaard's Drawing transparent bitmaps[^] It might give you the clue you need it to figure out where the real problem is... Best regards, Mihai Moga

      1 Reply Last reply
      0
      • C cherrymotion

        Hi guys, I have a dialog box on mfc and put a picture control onto it. Now it is no problem to load images from a path of my harddisk, they are shown well. But i dont know, how to load BITMAPS dynamically into the control. First I create a new Bitmap with the CreateBitmap() function from a Byte-Array. The function returns a non-zero value, so it was successfull. But now i have somehow to copy that bitmap into a memory-hdc, and from there i should be able to load it into the control. but i dont get it!!! I added a variable to the control from the type CStatic. But why is it so complicated, to get that created HBITMAP onto the Control? I mean, there IS a CStatic-function, which lets me SetBitmap(HBITMAP hBitmap)... But it does not work!!! I hope someone can help me... Best regards, cherry :doh:

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        cherrymotion wrote:

        I mean, there IS a CStatic-function, which lets me SetBitmap(HBITMAP hBitmap)... But it does not work!!!

        What if you call Invalidate() on the static control after you set its new bitmap? Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        C 1 Reply Last reply
        0
        • M Mark Salsbery

          cherrymotion wrote:

          I mean, there IS a CStatic-function, which lets me SetBitmap(HBITMAP hBitmap)... But it does not work!!!

          What if you call Invalidate() on the static control after you set its new bitmap? Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          C Offline
          C Offline
          cherrymotion
          wrote on last edited by
          #4

          Thanks for your help. But I didn't get further... I have to say, that my function is called after clicking a button. But that should make no problems I think?! That's my Code: CBitmap *cBitmap; HBITMAP hBitmap; cBitmap = new CBitmap(); PAINTSTRUCT ps; CDC *myCdc = m_whiteboard.BeginPaint(&ps); HDC memory = CreateCompatibleDC(NULL); CWnd* whiteWnd = m_whiteboard.GetWindow(2); CPaintDC paintDc(whiteWnd); hBitmap = CreateBitmap(iWidth,iHeight,1,8,pbFrame); bool succ = BitBlt((HDC)&paintDc,0, 0,iWidth,iHeight,memory,0,0,SRCCOPY); SelectObject(memory,hBitmap); Invalidate(true); ReleaseDC(&paintDc); m_whiteboard.EndPaint(&ps);

          C M 2 Replies Last reply
          0
          • C cherrymotion

            Thanks for your help. But I didn't get further... I have to say, that my function is called after clicking a button. But that should make no problems I think?! That's my Code: CBitmap *cBitmap; HBITMAP hBitmap; cBitmap = new CBitmap(); PAINTSTRUCT ps; CDC *myCdc = m_whiteboard.BeginPaint(&ps); HDC memory = CreateCompatibleDC(NULL); CWnd* whiteWnd = m_whiteboard.GetWindow(2); CPaintDC paintDc(whiteWnd); hBitmap = CreateBitmap(iWidth,iHeight,1,8,pbFrame); bool succ = BitBlt((HDC)&paintDc,0, 0,iWidth,iHeight,memory,0,0,SRCCOPY); SelectObject(memory,hBitmap); Invalidate(true); ReleaseDC(&paintDc); m_whiteboard.EndPaint(&ps);

            C Offline
            C Offline
            cherrymotion
            wrote on last edited by
            #5

            Is there another option to realize this?? I would be really happy if somebody helps me...

            1 Reply Last reply
            0
            • C cherrymotion

              Thanks for your help. But I didn't get further... I have to say, that my function is called after clicking a button. But that should make no problems I think?! That's my Code: CBitmap *cBitmap; HBITMAP hBitmap; cBitmap = new CBitmap(); PAINTSTRUCT ps; CDC *myCdc = m_whiteboard.BeginPaint(&ps); HDC memory = CreateCompatibleDC(NULL); CWnd* whiteWnd = m_whiteboard.GetWindow(2); CPaintDC paintDc(whiteWnd); hBitmap = CreateBitmap(iWidth,iHeight,1,8,pbFrame); bool succ = BitBlt((HDC)&paintDc,0, 0,iWidth,iHeight,memory,0,0,SRCCOPY); SelectObject(memory,hBitmap); Invalidate(true); ReleaseDC(&paintDc); m_whiteboard.EndPaint(&ps);

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              There's a bunch of things wrong there :) First you NEVER use a CPaintDC except in response to WM_PAINT (in OnPaint()). A CPaintDC is not valid in any other place. Second, I can't tell how you're trying to create the bitmap, but your calls are out of order. I'm not even sure how to correct it without knowing what you want the bitmap to be. Third, there's no code shown that has anything to do with setting a picture control's bitmap, which I thought was the original problem. What are you trying to do? Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              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