Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » adding a windows icon to the exe

Credits go to Audric, DanielH, ImLeftFooted, and verthex for helping out!
This thread is locked; no one can reply to it. rss feed Print
adding a windows icon to the exe
Mark Oates
Member #1,146
March 2001
avatar

I've read the wiki article and searched on the forums but haven't been able to get an icon into my windows exe.

My understanding is that I create an icon. (.ico file), then compile that icon into a resource file using windres.exe. My result is only slightly larger in size than my icon file, so I assume that part worked correctly.

Then I just link that resource into my exe when I compile the program. This appears to be the part where it doesn't work correctly. I'm using Code::Blocks and under Project>Build Options...>Linker Settings tab>Other linker options, I append the filename of my resource file, "icon_rc.res".

so, using openlayer, my "other linker options" looks like:
-lopenlayer -lglyph-agl -lfreetype -lpng -lz -lagl -lalleg -luser32 -lgdi32 -lglu32 -lopengl32 icon_rc.res

I tried including the "icon_rc.res" file in the directory with my programs files, and the mingw/bin directory, neither worked.

What am I missing?

Do I need to WinMain()?

On a side note, is it possible to get an icon working for multi-platform?

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Audric
Member #907
January 2001

Winmain is not needed.
Multi-platform is not possible.

Make sure your resource file starts with "1 ICON ", because the linker will only search for a resource called "ICON".

Are you sure you're not linking the resource file (text) instead of the generated .o file ?

Mark Oates
Member #1,146
March 2001
avatar

the resource file "icon.rc" is:

#include <windows.h>
allegro_icon  ICON  fullscore_icon01.ico

so I run at the command line "windres -O coff -o icon.res -i icon.rc" inside the directory with the icon.rc and fullscore_icon01.ico in that same directory.
{"name":"599493","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/e\/be985aca9f18769e52e634699838499d.png","w":522,"h":263,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/e\/be985aca9f18769e52e634699838499d"}599493

and the compiled result is "icon.res" which I rename to "icon_rc.res" and put into the bin lib folder:

C:\Program Files\CodeBlocks\MinGW\lib

then I try an compile the program with that above "other linker options" list and... nothing.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Audric
Member #907
January 2001

Well, no idea then... I'm more familiar with the variant I use for a program that doesn't use Allegro (SDL instead). It's with Mingw compiler tools and GNU Make, in Makefile :

# Resources (icon)
WINDRES = windres.exe
# Link the icons to the program under windows
$(OBJDIR)/winres.o : gfx2.ico
        echo "1 ICON \"gfx2.ico\"" | $(WINDRES) -o $(OBJDIR)/winres.o

And $(OBJDIR)/winres.o is one of the input files for the linker.

Seems very similar, only big difference is I use a pipe to feed the "resource script", and my resulting object has file extension .o instead of .res. I don't know if the file extension matters... And it's surprising that you get no error message, just a standard executable icon in the explorer.

DanielH
Member #934
January 2001
avatar

change it to "allegro_icon" with the quotes and try it again

Mark Oates
Member #1,146
March 2001
avatar

I tried "allegro_icon" with the quotes, and that didn't seem to work. :(

I've attached the resource file and the icon, would somebody check that these are working?

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

verthex
Member #11,340
September 2009
avatar

I think maybe you need this instead

windres -i icon.rc -o icon.o

I got it from this site. Hope it helps!

UPDATE: Heres another one.

Audric
Member #907
January 2001

According to one man page of windres (link) the ".res" and ".o" are normally different file extensions for different formats.
It's a bit strange that the wiki page recommends using "-O coff" (produce a linkable COFF object - usually with file extension .o) and call the output file icon_rc.res
Maybe the linker is then fooled by the file extension.
What complete command-line do you get for the linkage? Code::Blocks should output it somewhere.

Note that the output of windres is a normal generated object, specific to this project, just like foo.o you compile from foo.c ... you don't have to put it in lib/ folder.

edit
Ok I tested the icon_rc.res you attached above, and it works. I linked it to one of my Allegro games, just mentioning it as one of the object files.
After linking, the icon appears in the explorer (because it's the first icon resource) and as the window and task icon (because it correctly has the "allegro_icon" identifier, so allegro finds and "hooks" it).

So the problem must be in how you tell Code::blocks to link it.
Maybe Code::blocks already provides a different icon to the linker?
What is the complete command-line for the compiler ?

I've seen that that Dev-cpp also names the output of WINDRES, in COFF format, as "something.res"; so this file extension is not a problem for the linker.

ImLeftFooted
Member #3,935
October 2003
avatar

You got the right approach but you just have press the keys harder while you do it.

Mark Oates
Member #1,146
March 2001
avatar

Audric said:

So the problem must be in how you tell Code::blocks to link it.
Maybe Code::blocks already provides a different icon to the linker?

Ah-HA! That's it!

All I had to do was add the .rec file to my Code::Blocks project. Code::Blocks automatically put it in a "Resources" folder and then links it automatically. Go figure ::)

{"name":"599507","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/8\/9831d8abcf180add1b63105451c0a1b6.png","w":258,"h":547,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/8\/9831d8abcf180add1b63105451c0a1b6"}599507

Thanks everybody! :)

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Go to: