Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Give me a step-by-step guide on adding icons!

This thread is locked; no one can reply to it. rss feed Print
Give me a step-by-step guide on adding icons!
otah007
Member #15,801
November 2014

I'm looking to add an icon to my Allegro game (by that I mean the picture on the taskbar/window) and it's working...kind of. I've finally figured out how it all works, and when i click my .exe in windows explorer or on my desktop it has the icon I want, but it won't appear on the window itself. Here's what I've done so far (that's worked):

1) Created a .ico file from a .png, called "icon.ico"
2) Created a file called "icon.rc" that contains the following:
ALLEGRO_ICON ICON icon.ico
3) Used Developer Command Prompt for MSVC 2013 to compile "icon.res":
rc -fo icon.res icon.rc
4) Added "icon.res" to the linker options of my project

So to clarify: Windows clearly recognises the icon, but Allegro doesn't. What's wrong? :'(

EDIT: Seems I've got the taskbar icon showing up, at the cost of the .exe icon (but it shows it when you highlight it in windows explorer...weird). For some reason it worked once, then suddenly changed to the Allegro alligator - I have no idea how to change it back! Help me!

jmasterx
Member #11,410
October 2009

pkrcel
Member #14,001
February 2012

I assumed that if you compile the icon into the executable it should automatically get set also in the title bar of the window... I guess this means that's not true?

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

torhu
Member #2,727
September 2002
avatar

Yes, it's only because Allegro 4 loads the icon resource called "allegro_icon" and sets it as the program icon. Explorer loads the first icon, no matter the name.

EDIT: If you want to use the same icon in both cases in A5:

#ifdef ALLEGRO_WINDOWS
  HWND winhandle;
  HICON icon;
#endif
...
#ifdef ALLEGRO_WINDOWS
  icon = LoadIcon(GetModuleHandle(NULL), "IDI_ICON1");
  if (icon) {
    winhandle = al_get_win_window_handle(display);
    SetClassLongPtr(winhandle, GCLP_HICON, (LONG_PTR)icon);
    SetClassLongPtr(winhandle, GCLP_HICONSM, (LONG_PTR)icon);
  }
#endif

This will load both the 16x16 and the 32x32 icon, so there will be no resizing.

Go to: