Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Game icon

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Game icon
AleX-G Squadron
Member #13,593
October 2011
avatar

I wanted to configure my game app to have an icon
I mean only the icon of the executable on windows
I saw this link on the wiki about MSVC but i dont understand it

http://wiki.allegro.cc/index.php?title=Set_a_windows_icon#Compiling_with_MSVC

Can anyone give an example?
Thanks

www.anothergames.com

NiteHackr
Member #2,229
April 2002

Create resource.rc

put this in it:

ALLEGRO_ICON ICON "my_icon.ico"

Create resource.h

put this in it:

#define IDI_MYICON 1

Add both files to your project, include the header and compile and you should have a nice icon.

Incidentally, I like to use the free software IcoFX to create my icons with. Great little program will create all the sizes you need and save as a proper icon.

Edit: Hmph, IcoFX USED to be free, looks like they made v2 pay. Glad I downloaded it when I did.

Edit2: You can download the old FREEWARE version (1.6.4). I updated the above link to point to it instead. They made a new version 2 and are charging $50 for it... from FREEWARE to $50+?!?! isane.

This is a good reason why I like to back up things I download onto DVD rather than relying on them always being there online. I think I'll buy a solid state drive and start backing up more often.

--
Deluxe Pacman 1 & 2 (free) with source code available
https://nitehackr.github.io/games_index.html

AleX-G Squadron
Member #13,593
October 2011
avatar

Shall i add the lines of code with notepad?
Because in visual studio, it wont let you write on .rc files.
I tried with notepad adding your lines of code, added a my_icon.ico
in the project folder and in the debug folder, added the #include
<resource.rc> and <resource.h> but the project didnt succeed the build.
Am I missing something?

www.anothergames.com

torhu
Member #2,727
September 2002
avatar

You can open .rc files in msvc by right-clicking and selecting "View Code" (I'm using msvc 9 express).

You don't need a header file, you just need the RC. This is enough:
IDI_ICON1 ICON "my_icon.ico"

Put the .ico in the same folder as the .rc. The header file is for turning the name constants into numbers, but you can load resources using the name string directly too (see below). Add the file to the solution in msvc, which will automatically compile it into a .res file and link with it when building your project.

As far as I can tell, Allegro 5 doesn't have the automatic icon loading that Allegro 4 had. So unless you do some extra work, the icon will only be used by Explorer. Explorer just loads the first icon resource it finds in the file. But it won't become the window icon automatically.

I use this code for setting the window icon using the same icon resource:

#ifdef ALLEGRO_WINDOWS
  HWND winhandle;
  HICON icon;
#endif

And later:

#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

You have to create the display first, obviously ;D

AleX-G Squadron
Member #13,593
October 2011
avatar

I dont know i get this:
{"name":"606512","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/1\/d1b08a7b10a0c706107ca375817581be.png","w":1280,"h":180,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/1\/d1b08a7b10a0c706107ca375817581be"}606512

And where do you put your code, inside your .rc file or .cpp?
I copy paste it and i get what you see in the image

www.anothergames.com

Arthur Kalliokoski
Second in Command
February 2005
avatar

What are the permissions on this resource.rc file? And do you have extensions hidden, so it's actually "resource.rc.txt"?

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

AleX-G Squadron
Member #13,593
October 2011
avatar

There is no .txt at the end and i usually get something like Opened in another text editor when there is no text editor opened
The permissions are all granted

{"name":"606513","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/9\/e9049b308f6a1623d4be1c4c6f08322f.png","w":353,"h":80,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/9\/e9049b308f6a1623d4be1c4c6f08322f"}606513

I also get this when i try to click on it

{"name":"606514","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/d\/ad8f7052be5418a216e18c703ce14285.png","w":492,"h":246,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/d\/ad8f7052be5418a216e18c703ce14285"}606514

www.anothergames.com

NiteHackr
Member #2,229
April 2002

You need to rename it to "resource.rc" and get rid of that (1). That means you have two versions of it in the same folder, choose one of them and add that line to it and delete the other.

Also, if it states it is already open, you probably still have an editor open that you used to add the line with. Save it and then close the editor so you only have MSVC running.

Or switch to using something like CodeBlocks and a GNU compiler. ;)

--
Deluxe Pacman 1 & 2 (free) with source code available
https://nitehackr.github.io/games_index.html

Trent Gamblin
Member #261
April 2000
avatar

I use IcoFX too. $50 just for that? That's unreasonably high. I'll just continue using the free version I have while I can, then find something else (either free or not insanely priced just to convert icons.)

NiteHackr
Member #2,229
April 2002

I was curious about the file format for .ICO files, I wonder how hard it would be to make a simple conversion program using Allegro to create icons for people. Wouldn't have to be feature rich.

--
Deluxe Pacman 1 & 2 (free) with source code available
https://nitehackr.github.io/games_index.html

Arthur Kalliokoski
Second in Command
February 2005
avatar

I thought there was an icon utility in A4?

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Trent Gamblin
Member #261
April 2000
avatar

The only unique feature of IcoFX (though there are probably other programs that do this) is it can store any number of different sized icons in the same .ico file. I usually store a 48x48 (XP) and 256x256 (Vista & 7).

Specter Phoenix
Member #1,425
July 2001
avatar

Do you not use icons (ico) for Linux? I've not really messed with them before.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)
"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix
"Programming == AWESOME the rest is just tools to accomplish it."
END OF LINE

Trent Gamblin
Member #261
April 2000
avatar

No, they're mainly a Windows thing. Only other place I've ever seen them is website icons (the little ones in the url bar.)

LennyLen
Member #5,313
December 2004
avatar

NiteHackr said:

I was curious about the file format for .ICO files, I wonder how hard it would be to make a simple conversion program using Allegro to create icons for people. Wouldn't have to be feature rich.

An .ico file is pretty much just a .bmp file with a flag set in the header. I have functions written for A4 for loading/saving .cur files which could be easily adapted since .cur is also the same format.

Thomas Fjellstrom
Member #476
June 2000
avatar

LennyLen said:

An .ico file is pretty much just a .bmp file with a flag set in the header. I have functions written for A4 for loading/saving .cur files which could be easily adapted since .cur is also the same format.

Gotta love the RIFF format. AVI's are also RIFF[1]. But they don't share near as much of the structure as bmp, ico, and cur's do.

References

  1. .sf2 is also RIFF, but maaaann its got one hell of a messed up structure

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

LennyLen
Member #5,313
December 2004
avatar

The DIB structure (bmp, cur, ico) isn't RIFF format. The ANI animated cursor is though.

AleX-G Squadron
Member #13,593
October 2011
avatar

There is no resource.rc and i found out why it said still open.
I had notepad++ and closed all tabs then closed.

Still same problem, did exactly as you said.
{"name":"606515","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/e\/3efb5f8699f4222930bc016c7b044d79.png","w":625,"h":499,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/e\/3efb5f8699f4222930bc016c7b044d79"}606515

www.anothergames.com

Thomas Fjellstrom
Member #476
June 2000
avatar

LennyLen said:

The DIB structure (bmp, cur, ico) isn't RIFF format. The ANI animated cursor is though

Damn I don't know what in was thinking ::(

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

AMCerasoli
Member #11,955
May 2010
avatar

I knew there should be a tools like this on the internet. What bout this? http://www.icoconverter.com/ Not tested...

torhu
Member #2,727
September 2002
avatar

I use IcoFX 1.6.4, which is free.

AleX-G Squadron, what exactly is your current problem? Maybe there's something new about the way msvc 11 handles .rc files, but I can't see why you shouldn't be able to just add the .rc file to the solution and build.

AleX-G Squadron
Member #13,593
October 2011
avatar

I dont really get it.
I get so many errors for the icon.
But i think it has to do with MSVC 2012 as you guys say it is easy!
{"name":"606517","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/a\/aa74f9a82966209ea3c2814dde578767.png","w":1280,"h":961,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/a\/aa74f9a82966209ea3c2814dde578767"}606517

www.anothergames.com

Specter Phoenix
Member #1,425
July 2001
avatar

From what I remember of MSVC++ it has always been fairly easy to include them assuming you are meaning something like this from 2006 ( http://www.gamedev.net/topic/379876-setting-the-compiled-programs-icon-in-visual-studio/ ). Though, if this is something for you book, then you shouldn't be worrying about this as Icons again have nothing to do with C++ nor Allegro.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)
"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix
"Programming == AWESOME the rest is just tools to accomplish it."
END OF LINE

AleX-G Squadron
Member #13,593
October 2011
avatar

Ok, at least less work
But the more i know the better it is! ;D
Though i remember making C# programs icons very easy.
Here i have to add allegro coding lines,
but how comes there are allegro commands when that has nothing to do with allegro?
:o

Anyone can find any video who shows how to do it?
I dont have time to waste on an icon!

Meanwhile enjoy this video...
http://www.youtube.com/watch?NR=1&feature=endscreen&v=WAnERyiaYXU

www.anothergames.com

torhu
Member #2,727
September 2002
avatar

If you upload your source code and everything needed to build your game, I can make an msvc 9 project that you can probably open with msvc 11. You don't need to upload Allegro, just tell me exactly what files I need to link with.

 1   2 


Go to: