0
votes

I'm a little bit confused about Visual Studio (2013) resource files. I added a new bitmap to my project, it has it's own symbol, IDB_BITMAP1, though I'm not sure how to use it in MAKEINTRESOURCE macro. I have to use its number id, 101. I opened resource.h file with notepad and there is no #define directive for that. Do I have to manually add constants for my resource files or does VS do it automatically for me and I just miss something?

2

2 Answers

1
votes

This is a typical way of doing it:

Header file:

// resources.h
#ifndef _RESOURCES_H
#define _RESOURCES_H

#define IDB_BITMAP1 101

#endif

Resources file:

// resources.o
IDB_BITMAP1 BITMAP DISCARDABLE ".\myPic.bmp"

Source-code:

// other_file.cpp
#include "resources.h"
HBITMAP hBitmap = (HBITMAP) LoadImage(
    hInstance,
    MAKEINTRESOURCE(IDB_BITMAP1),
    IMAGE_BITMAP,
    0,
    0,
    LR_LOADFROMFILE);

Don't forget to release the memory, by doing

DeleteObject(hBitmap);

when the bitmap is no longer used.

1
votes

Actually I realized now, that adding a file doesn't modify resource.h file. I had to include it, use file's id in MAKEINTRESOURCE and just hit compile button, then it works.