Most recent wxInclude release ?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Most recent wxInclude release ?

Post by eranon » Sun Apr 21, 2013 1:06 pm

Hello. I'm managing to embed some PNG images in my project's code (I prefer a cross-platform way rather than going with resource). So, and because I would like to keep these images in a single header file, I use wxInclude ; the one downloaded following the link from http://wiki.wxwidgets.org/Embedding_PNG_Images.

Well, however, the macros and inline functions wxInclude generates seems to be wrong and don't compile (currently under Windows, wxWidgets 2.9.4 and GCC) ; call doesn't match wxImage ctor prototypes (don't remember the exact error, but something like a long integer which should be a wxString).

So, I've commented the functions and macros produced by wxInclude and written the ones advised in the wiki :

Code: Select all

#define wxGetBitmapFromMemory(name) _wxGetBitmapFromMemory(name ## _png, sizeof(name ## _png))

 inline wxBitmap _wxGetBitmapFromMemory(const unsigned char *data, int length)
 {
   wxMemoryInputStream is(data, length);
   return wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1);
 }
De facto, my questions are :

Is there an up-to-date wxInclude somewhere ? The one I talk here seems to be compiled on 2007.
Or, is there an easy way to produce several image declarations in a single header (.h) from bin2c or png2wx ?
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]

eranif
Moderator
Moderator
Posts: 607
Joined: Tue Nov 29, 2005 7:10 pm
Location: Israel

Re: Most recent wxInclude release ?

Post by eranif » Sun Apr 21, 2013 4:24 pm

Have you considered using wxrc for this purpose?

1. Create a XRC file with the following content (call it resources.xrc)

Code: Select all

<resource>
   <object class="wxBitmap" name="test">C:\src\images\test.png</object>
</resource>
2. Convert the XRC file into C++ file, by typing from the command line the following:

Code: Select all

wxrc /c /v /o resources.cpp resources.xrc
this line will produce file name resources.cpp - add it to your project

3. In your code, add this line somewhere in the initialization of your application (App::OnInit() maybe):

Code: Select all

// this function is located inside the resources.cpp file
extern void InitXmlResource(); 

// initialize the images from the xml resource file
InitXmlResource();

4. Now you are ready to use the images in your code:

Code: Select all

//load image from the resources manager
wxBitmap bmp = wxXmlResource::Get()->LoadBitmap(wxT("test");
Eran
IDE: CodeLite + wxCrafter
OS: All
https://wxcrafter.codelite.org
https://codelite.org

User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Most recent wxInclude release ?

Post by eranon » Mon Apr 22, 2013 11:31 am

Yes, it's also a way and thanks for this detailled tuto Eranif, but it's one step more than going from PNG to C array through bin2c or wxInclude directly. But maybe there're some considerations I've missed... Let me know...

At this stage, all sounds right with wxInclude. I've simply used its "--noheader --wxnone" options to do it only produce the data arrays and nothing more. Also, I've moved the required macro and inline functions in a global.h I already have for this project.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]

Post Reply