Page 1 of 1

How to include BMP. ICO files in project

Posted: Wed Oct 15, 2008 5:42 pm
by valiyuneski
Hi i was wondering how to include resources like BMP , ICO and so on in the project ?

Re: How to include BMP. ICO files in project

Posted: Wed Oct 15, 2008 6:01 pm
by eranif
Which framework do you use? (I can help you with wxWidgets...)

Eran

Re: How to include BMP. ICO files in project

Posted: Wed Oct 15, 2008 6:44 pm
by valiyuneski
wxWidgets it is indeed !!!

(i am also jewish and grew up in ISRAEL for 24 years)

Re: How to include BMP. ICO files in project

Posted: Wed Oct 15, 2008 7:52 pm
by eranif
This is how I adds icons to CodeLite using wxWidgets:

1. create a .xrc file, name it resources.xrc (the name does not matter here).

Copy the following to it:

Code: Select all

<resource>
	<object class="wxBitmap" name="my_image_name">/full/path/to/image/file</object>
</resource>
Where: /full/path/to/image/file is the image file on your machine (e.g. C:\Devel\picture.bmp)

2. add this file to your project.

3. create an empty file, name it resources.cpp and add it to the project as well (make sure that resources.xrc and resources.cpp are at the same path)

4. open the project settings, and switch to the 'Custom Makefile Steps' tab.
enter this:
Dependencies: resources.cpp
Rule action:

Code: Select all

resources.cpp: resources.xrc
<TAB>wxrc -c -v -o resources.cpp resources.xrc
Note that <TAB> is the my way to tell you to place there a TAB character.

5. from the command line, do this:

Code: Select all

touch resources.xrc
and compile your project - CodeLite at this point should run the wxrc command for you and generate the resources.cpp file.

6. At this point, your resources.cpp will contains a generated code which is the converted image into C array.

7. Add this code to your OnInit() method of your wxApp derived class:

Code: Select all

//at the top of your wxApp derived class, add this code
#include <wx/xrc/xmlres.h> // for wxXmlResource
extern void InitXmlResource();

bool MyApp::OnInit()
{
      ...
       // inside your OnInit method of wxApp derived class, add this code
       wxXmlResource::Get()->InitAllHandlers();
	wxImage::AddHandler( new wxPNGHandler );
	wxImage::AddHandler( new wxCURHandler );
	wxImage::AddHandler( new wxICOHandler );
	wxImage::AddHandler( new wxXPMHandler );
	wxImage::AddHandler( new wxGIFHandler );
	wxImage::AddHandler( new wxBMPHandler );
	InitXmlResource();
        ...
}
To use your image:

Code: Select all

wxBitmap bmp = wxXmlResource::Get()->LoadBitmap(wxT("my_image_name"));
From this point on, every time youmodify the resources.xrc file - building the project will force a regeneration of the resources.cpp.
You can add as many images as you want to the resources.xrc file.

HTH,
Eran