7
votes

Is it possible to load a *.bmp file into a HBITMAP in a Win32 project, using only WINAPI functions?

2

2 Answers

16
votes

Yes, it is possible using only the standard win32 library.

HBITMAP hBMP = (HBITMAP) LoadImage( NULL, "Your/ImagePath/a.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

hBMP is a handle to the BITMAP to use as you want.

Note: It is important to pass NULL as the first argument, from the docs:

hinst [in, optional]

To load a stand-alone resource (icon, cursor, or bitmap file)—for example, c:\myimage.bmp—set this parameter to NULL.

From the msdn documentation for LoadImage.

0
votes

Yes, you can use the OleLoadPictureFromPath or whatever it was called. Check it. The docs are probably still inconsistent and wrong about supported formats but in modern Windows also JPEG and PNG supported.