-
May 3rd, 2012, 11:30 AM
#1
Displaying a bitmap from memory to a Dialog or CStatic
Dear Experts.
Im trying to Display BMP file, but that is stored in a buffer in memory I dont want to write it down to a file to re-open later im trying to find an elegant solution since I want to save system resources.
well I found this article but im not that experienced with Device contexts and HBitmaps.
I found this article at code guru:
http://www.codeguru.com/cpp/g-m/bitm...a-BMP-file.htm
it looks like exaclty what i need it loads it from a file but its ok i can modify that latter but my problem is that i dont quite understand it, for example:
void DrawDIB( CDC* pDC, HGLOBAL hDIB, CPalette *pPal )
this is the function that should draw the image but it receives a CDC* pDC what would be the difference with a HDC.
also how would i use this function to display that file to a CStatic or even the in the Dialog body would work for me.
Thx in Advance!!
-
May 3rd, 2012, 12:16 PM
#2
Re: Displaying a bitmap from memory to a Dialog or CStatic
Maybe I have understood you not 100% correct, but if you want to dissplay a bitmap from some file on the static control you do:
- Set the SS_BITMAP style to this static (or "picture") control
- Load the bitmap from file using LoadImage API
Code:
HBITMAP hBmp = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE ); -
Then you use MFC method CStatic::SetBitmap or send the STM_SETIMAGE to set the bnitmap to the static control.
Victor Nijegorodov
-
May 3rd, 2012, 01:01 PM
#3
Re: Displaying a bitmap from memory to a Dialog or CStatic
Originally Posted by VictorN
Maybe I have understood you not 100% correct, but if you want to dissplay a bitmap from some file on the static control you do:
- Set the SS_BITMAP style to this static (or "picture") control
- Load the bitmap from file using LoadImage API
Code:
HBITMAP hBmp = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE ); -
Then you use MFC method CStatic::SetBitmap or send the STM_SETIMAGE to set the bnitmap to the static control.
thx for ur answer
May be i didnt explain myself properly what i dont understand is where do i get the CDC* from my CStatic to draw there.
in few words i need to make this example work cause i need the way it loads the Bitmap it would allow me to do the same from a buffer which i woulnt using LoadImage.
thx again for ur time
-
May 3rd, 2012, 01:18 PM
#4
Re: Displaying a bitmap from memory to a Dialog or CStatic
Hi.
You must get the CDC in the OnPaint function and draw the image.
Best regards.
-
May 3rd, 2012, 02:03 PM
#5
Re: Displaying a bitmap from memory to a Dialog or CStatic
juanpast is right!
you should derive your own class from CStatic, implement the WM_PAINT message handler in this derived class and use the device context (CPaintDC ) it provides for you.
Victor Nijegorodov
-
May 3rd, 2012, 03:00 PM
#6
Re: Displaying a bitmap from memory to a Dialog or CStatic
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|