HOW TO CREATE AND ADD RESOURCE FILES INTO PROJECTS
Consider a sample project with three files involved:
- a CPP header file which is included in the resource file.
- the resource file itself.
- the main CPP program file.
I am making the supposition that you know how to create an header file and the main program file, but... You should have some knowledge about how to write .rc files, before to use them. If you need more informations about resources.rc files here's the msdn documentation, then how to create a resource file?
CREATING A RESOURCE FILE
- Create a new file in a way that would be easiest for you, for example: Click on File menu, then New File, Other type File and finally select an Empty File.
- Select a proper name for your resource file and click on Finish.
- Write the code for your resource file and Save changes (for this tutorial I have chosen resource.rc).
ADDING A RESOURCE FILE INTO A PROJECT
Now we have all three files and so we will add resource.rc into our project using the following steps:
- Right-click on resource.rc and select properties. Now we are in File Propierties - resource file.
- On Categories -> General be aware that in Item Configuration under Tool you want to be sure Custom Build Tool is selected in list.
- Fill out the following fields as shown below:
- Command Line: windres.exe resource.rc resource.o
- Since I am using MinGW I will use MinGW’s resource compiler windres.exe. You should enter the resource compiler you are currently using with its proper options.
- Description: Compiling resources…
- Here you can optionally write text which will be printed on screen during project’s compiling process.
- Outputs: resource.o
- Outputs are files generated by the command line we have entered before, in this case the only output is resource.o.
- Additional Dependencies: ids.h
- In this option we write files which are included into our resource file. (i.e. #include “ids.h”).
- Apply changes and press OK button.
- At this point we need to setup project’s properties: right-click on project’s name and select Properties, then click on Linker configuration.
- Click on Libraries, then on Add Option, select Other Option, finally enter the name of the compiled resource file, in this case resource.o, and press OK button.
- Next step consists of adding Additional Dependencies from Project Propierties context menu (see step number 5) , enter the resource file’s name and press OK button.
- Finally we must Apply changes and press OK button.
Thus we have added a resource file (resource.rc) into our project.
Created by Novalida 2009
Edited by piBYe July 31 2009