简体   繁体   中英

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?

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" 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM