How do I display a bitmap in a window in Win32??

How do I load a bitmap from a file and display it in Win32? I know of BITMAPINFOHEADER and BITMAPFILEHEADER, and I know how to open a file in binary read mode, but not how to read in the actual image. I have read up on CreatCompatibleDC and know how to use it, but my help files only show how to save an area of memory to a file after determining colors and such, not how to load one. It also explains how to stretch one, but once again, no help there. Could somebody please explain to me the ONE step I am missing? Thanks in advance for any help you can provide. Oh, and I need to know how to load it from a file during execution, because I am writing a 3D engine and will need to load hundreds of different ones.



  • : How do I load a bitmap from a file and display it in Win32?

    Use LoadImage.

    [code]HBITMAP h = (HBITMAP)LoadImage(NULL, "c:\test.bmp", IMAGE_BITMAP,
    0, 0, LR_LOADFROMFILE);[/code]


  • /*Put this in you resource file:*/

    BITMAP_ID BITMAP bitmapfile.bmp

    /*Declare a handle to your bitmap:*/

    HBITMAP hBitmap;

    /*Use the LoadBitmap() func:*/

    hBitmap = LoadBitmap(hThisInst, "BITMAP_ID");

    /*Use the functions you already know.*/

  • Thanks to both of you for that information. LoadImage should do the trick. I REALLY appreciate this!


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!