The Allegro Wiki is migrating to github at https://github.com/liballeg/allegro_wiki/wiki

Set a windows icon

From Allegro Wiki
Jump to: navigation, search

To assign an icon to your executable file in Windows, one option is to use the wfixicon tool in your Allegro installation. This program takes a bitmap as argument and can output an icon file and resource script. While this is acceptable, it outputs a very old format of icon. "Modern" operating systems like Windows XP can handle alpha channels in icons, and wfixicon will not allow this.

Creating an Icon

It is suggested that you use a tool to generate your own .ico file. Gimp can generate .ico files wonderfully. .ico files can store more than just one icon inside. This way larger and smaller icons can be displayed without Windows having to resize the original -- a task it usually does poorly. With Gimp, each layer in the image will be saved as a different icon. This is a very useful feature.


Creating a Resource Script

To add your icon to your game, you first must make a resource script -- it's really easy to do. Make a new file with this single line in it:

 ALLEGRO_ICON ICON icon.ico

Replace icon.ico with whatever your icon filename is. You can save this as "icon.rc", or anything else you like. This file is called the resource script. Before it can be used, it must be compiled. That is a compiler-specific task.


Compiling with MinGW

Make sure that the MinGW bin directory is in the path. If you compiled Allegro yourself, it should be. Execute the following command:

 windres -O coff -o icon.res -i icon.rc

icon.res is the output file, and icon.rc is the input.

Compiling with MSVC

Make sure that the MSVC environment variables are set. This is done with the vcvars32.bat file. Again, if you compiled Allegro yourself, you should be somewhat familiar with this procedure. Execute the following command:

 rc -fo icon.res icon.rc

icon.res is the output file, and icon.rc is the input.

Compiling with Borland C++

 brc32 -r -fo icon.res icon.rc

icon.res is the output file, and icon.rc is the input.


Linking

Finally, to make this icon your program's icon, simply link the compiled .res file with your application.