MrMcSniper
MrMcSniper

Reputation: 41

How to load a bitmap from a resource file (.rc file)?

I am programming a simple game in visual studio and I have set up a resource file (.rc file) i am also using sdl2. I am wondering if there is a way to load or draw the bit maps located in the resource file. Thanks in advance

I am currently using this line:

HBITMAP hBtMpIMG = LoadBitmap((HINSTANCE)getModuleHandle(_T("Project 1.exe")), MAKEINTRESOURCE(IDB_BITMAP1));

How would I render the hBtMpIMG using sdl2?

Upvotes: 2

Views: 9282

Answers (1)

Raindrop7
Raindrop7

Reputation: 3911

You can use the API: LoadBitmap to load a bitmap stored in the executable:

    case WM_CREATE:
    {
        HBITMAP hBtMpBall = LoadBitmap((HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), MAKEINTRESOURCE(IDB_BALL)); //Here we have to use the executable module to load our bitmap resource
        //this means that this resource "ball.bmp" is compiled and stored in the executable module"
        //however if you use loadimage you can ignore this module and makeit null because you are laoding from file

        if(!hBtMpBall)
            MessageBox(0,"ball.bmp not found!",0,0);
    }
    break;
  • In a resource file: .rc you may have like this:

    #include "myres.h"
    
    IDB_BALL BITMAP DISCARDABLE "ball.bmp"
    

Upvotes: 3

Related Questions