Jump to content
  • Advertisement
Sign in to follow this  

Loading BMP from resource

This topic is 4846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, I dont know about directX9, but this may help.
Windows has a nifty LoadImage function that can either load an image from file or a resource:

First off, you need to create 2 variables, a bitmap object, and a bitmap handle:
HBITMAP BitmapHandle;
BITMAP Bitmap;

Next, you get the handle of the bitmap using the load image function. A link to the online MSDN page on this function is posted below:


HANDLE LoadImage( HINSTANCE hinst, //The Window Handle
LPCTSTR lpszName, //The Name of the Bitmap (or resource ID)
UINT uType, //The Type of Image
int cxDesired, //The Desired Width (0 for all)
int cyDesired, //The Desired Height (0 for all)
UINT fuLoad //Loading Flags

The call to the function would look something like this:

BitmapHandle = (HBITMAP)LoadImage( HInstance, MAKEINTRESOURCE(ResourceID),

Where HInstance is the instance of the window and ResourceID is the ID of the resource.

Next, you have to get the actual bitmap from the handle, by calling the GetObject Function:


int GetObject(
HGDIOBJ hgdiobj, // handle to graphics object
int cbBuffer, // size of buffer for object information
LPVOID lpvObject // buffer for object information

The call looks like this:
GetObject(BitmapHandle, sizeof(Bitmap), &Bitmap);

As for actually adding the bitmap to the surface, I can't really help you there. In DX7, you create a compatible DC and just Blt the bitmap to the surface. However, in DX9, you might have to use it as a texture.

Make sure to delete the object when you are done with it:


Hope this helped.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!