Displaying a bitmap from memory to a Dialog or CStatic

Printable View

  • May 3rd, 2012, 01:01 PM
    Alphadan
    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
  • May 3rd, 2012, 01:18 PM
    juanpast
    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
    VictorN
    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.
  • May 3rd, 2012, 03:00 PM
    Alphadan
    Re: Displaying a bitmap from memory to a Dialog or CStatic
    thx gonna try it