Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Allegro 4 - allegro_icon

This thread is locked; no one can reply to it. rss feed Print
Allegro 4 - allegro_icon
Andrew Gillett
Member #15,868
January 2015

I realise this is pretty oldschool, but - the Windows page of the Allegro 4 manual says:

"When creating the main window, Allegro searches the executable for an ICON resource named "allegro_icon". If it is present, Allegro automatically loads it and uses it as its application icon; otherwise, Allegro uses the default IDI_APPLICATION icon."

I have an icon of that name in the resources, and it displays on the EXE, but it doesn't get displayed as the application icon.

The relevant code in wwnd.c is:
wnd_class.hIcon = LoadIcon(allegro_inst, "allegro_icon");

It appears that this is returning null.

Please let me know if there is a better place to post this.

torhu
Member #2,727
September 2002
avatar

What does your .rc file look like?

Andrew Gillett
Member #15,868
January 2015

The relevant line from the .rc file looks like this:

allegro_icon ICON "build\\icon256.ico"

My current workaround is:

HICON i = LoadImage(nullptr, "icon256.ico", IMAGE_ICON, 256, 256, LR_LOADFROMFILE|LR_SHARED);
if (i)
{
SendMessage(hWnd, WM_SETICON, ICON_BIG, (int)i);
}
HICON i16 = LoadImage(nullptr, "icon16.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE | LR_SHARED);
if (i16)
{
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (int)i16);
}

(I have yet to discover how to create an icon file containing icons of different sizes - or rather, MSVC's icon editor lets me do that, but can't see how to actually import bitmaps into icons using that. Currently using FormatFactory for conversion, but that doesn't seem to allow multiple icons per .ICO)

torhu
Member #2,727
September 2002
avatar

I'm not sure why that wouldn't work, looks OK to me.

For creating icon files I used to use a program called IcoFX, I think 1.6.4 was the last free version of it.

ZoriaRPG
Member #16,714
July 2017
avatar

Try this:

allegro_icon ICON MOVEABLE PURE LOADONCALL DISCARDABLE "./build/icon256.ico"

Andrew Gillett
Member #15,868
January 2015

Unfortunately that didn't work.

ZoriaRPG
Member #16,714
July 2017
avatar

In MSVC, hold Control+Shift+E

This will shift you into 'Resource View'.

Open the tree for your project, and then the icon.cr tree, and the icon tre under that. Then, check if he icon resource is present.

If it is, right click it, and select 'Insert Icon'. That will allow you to view all of the icon modes, and edit them right there in MSVC. You should be able to copy an image in a gfx programme, and paste it into an icon type, there.

You can probably skip all of that extraneous code to load the icon in your game, and use this instead. I hope that this helps.

(Screenshot, attached)

<img src="http://zoriarpg.com/msvc/msvc-resource-view.png">

Someone remind me, please.... WTH is the correct tag format to embed an image? I tried a base <img> tag pair, and several forms of hypertext markup code. None of it worked?!

...or is it just the attachment, as I had thought but my file size is too large?

Andrew Gillett
Member #15,868
January 2015

This is what mine looks like (except I have now combined all 3 icons into one .ICO file):

https://argnet.fatal-design.com/share/psector-icon-msvc.png

ZoriaRPG
Member #16,714
July 2017
avatar

except I have now combined all 3 icons into one .ICO file

Does this mean that you have solved this issue? You should just be able to paste the icon data directly into MSVC, without the need of any external icon editor.

If your build isn't generating the icons where they belong, then check your .vcproj file, too. You want to see an entry similar to this:

<File
    RelativePath="C:\path_to\icon.rc"
>
</File>

That is, ensure that the resource script is properly embedded into the project.

For the sake of completion, you can also embed an icon in using allegro_icon, like this:

https://github.com/ArmageddonGames/ZeldaClassic/blob/2.55/zc_icon.c

That's for X-Windows (Unix/Linux).

Peter Hull
Member #1,136
March 2001

I tried and it seemed to work for me.
My .rc was just

allegro_icon ICON icon.ico

and the C code (it's been ages since I did any allegro 4)

#SelectExpand
1#include <allegro.h> 2 3int main(int argc, char *argv[]) 4{ 5 (void) argc; 6 (void) argv; 7 allegro_init(); 8 install_timer(); 9 install_keyboard(); 10 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 240, 0, 0); 11 rest(5000); 12 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); 13 return 0; 14} 15END_OF_MAIN();

I attached the icon I used.

I find ImageMagick is a good way to create multi-resolution icons, if you have the images you can just do:

magick image16x16.png image32x32.png image48x48.png icon.ico

and if you are lazy you can even get IM to create the individual images by resizing a larger master image.

EDIT: Just thinking, can you attach your icon? I'm wondering if LoadIcon is a bit picky on the size/colour depths it accepts because it's an 'old' API function.

Andrew Gillett
Member #15,868
January 2015

The entry in the vcxproj file looks like this:

<ItemGroup>
<ResourceCompile Include="psector.rc" />
</ItemGroup>

The icons display correctly on the EXE file but I still need my workaround for them to be used as the application icons while it's running.

You can find my icon file here:
https://argnet.fatal-design.com/share/psector.ico

Peter Hull
Member #1,136
March 2001

Your icon worked fine for me. Maybe it's related to the high dpi stuff? I am at a loss.
{"name":"611811","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/f\/0fd22f98120c2be96d8fc167c131161a.jpg","w":317,"h":194,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/f\/0fd22f98120c2be96d8fc167c131161a"}611811

Go to: