8

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

sashoalm
  • 75,001
  • 122
  • 434
  • 781

2 Answers2

18

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.

Dennis van der Schagt
  • 2,404
  • 2
  • 27
  • 33
Theocharis K.
  • 1,281
  • 1
  • 16
  • 43
  • That's an external library. –  Jan 15 '13 at 12:46
  • Er, by external I meant third-party libraries I guess. Will edit. Since it's a Win32 project, it already uses Winapi. Thanks for the answer! – sashoalm Jan 15 '13 at 12:47
  • @Zoidberg what are the standard libraries in Win32 projects? :S – Theocharis K. Jan 15 '13 at 12:52
  • Just one correction, hInst needs to be NULL for loading from file. I just read it in the docs. *To load a stand-alone resource (icon, cursor, or bitmap file)—for example, c:\myimage.bmp—set this parameter to NULL.* – sashoalm Jan 15 '13 at 12:54
0

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.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331