views:

70

answers:

4

I want to make an application, but the application will be using icons (bitmaps) for some of the menu buttons and other stuff. I want to keep my application as one simple, single standalone exe file which means I will somehow have to embed all of the icons into the application (EXE on windows) so I can load the bitmaps without having any external files.

Does anyone know how I can do this?

Just some other info: I'm using wxWidgets, currently with MSVC and I would prefer a method that works cross compiler/cross platform if possible.

Thanks in advance!

+4  A: 

You could used the XPM format for your bitmaps, as it's easy to embed in your code (which of course is going to be in the exe, right where you want it;-). As the docs say,

All wxWidgets platforms support XPMs for small bitmaps and icons. You may include the XPM inline as below, since it's C code, or you can load it at run-time

(the "as below" being a #include directive) -- so, you would be perfectly cross-compiler and cross-platform by adopting this approach with the "include" option.

For more info about the XPM format, see here. It's easy to find converters to XPM from other popular formats, of course.

Alex Martelli
Does XPM format support alpha channels?
Brad
@Brad, only transparency as an on/off option, I believe -- not the full, nuanced translucency offered by actual "alpha channels".
Alex Martelli
+1  A: 

Windows does have resource files.You could use that. Alternatively you could write a small utility that will convert your binary icon into a C constant array

eg:

const unsigned int my_icon[] = {0x12345678, 0x87654321, .... };

This could easily be done in perl and you can then access the icon with the variable my_icon.

doron
A: 

Cause Linux has no platform solution for this you will have to create your own system anyway. So i would recommand against platform specific ways to add resources on windows and macosx.

You can use reswrap which comes with the FOX GUI Toolkit is a simple tool to convert any binary file into c char literals. If you compile with msvc you will soon find that large files with lot of large strings are poison for the compiler. I added about 900 icons for my project and it killed the compiler.

I currently work with a solution where i simply copy a binary archive at the end of the executable. Every platform today can give you the executable path and neither ELF, EXE or Mach-O files care if additional data is added at the end of an executable file.

Lothar