CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2009
    Posts
    252

    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!!

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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:
    1. Set the SS_BITMAP style to this static (or "picture") control
    2. 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

  • #3
    Join Date
    Feb 2009
    Posts
    252

    Re: Displaying a bitmap from memory to a Dialog or CStatic

    Quote Originally Posted by VictorN View Post
    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:
    1. Set the SS_BITMAP style to this static (or "picture") control
    2. 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
  • #4
    Join Date
    Feb 2005
    Location
    Madrid (Spain)
    Posts
    511

    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.

  • #5
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  • #6
    Join Date
    Feb 2009
    Posts
    252

    Re: Displaying a bitmap from memory to a Dialog or CStatic

    thx gonna try it

  • Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •  





    Click Here to Expand Forum to Full Width

    Featured