HBITMAP to picture control
-
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:
-
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:
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
-
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:
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:
-
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:
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);
-
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);
Is there another option to realize this?? I would be really happy if somebody helps me...
-
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);
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: