![]() |
|
Icons |
SkaxCo
Member #8,323
February 2007
|
Can you store an icon inside a datafile and use it as the program icon? |
BAF
Member #2,981
December 2002
![]() |
Not to my knowledge. You should be able to use the fixicon program offered by Allegro and link with the generated object file to gain an icon. |
James Stanley
Member #7,275
May 2006
![]() |
You can but it's difficult and I haven't tried it. |
Ron Ofir
Member #2,357
May 2002
![]() |
What? I don't think you can set the icon using code, I think you must add it to the header of the .exe file (using resources or whatever). |
BAF
Member #2,981
December 2002
![]() |
What? Wfixicon gives you a resource file, and if you tell it to it will compile it for you. Then you just link with the object file. |
Ron Ofir
Member #2,357
May 2002
![]() |
Exactly, so it has nothing to do with datafiles, that, and you can save an icon file and then associate it later using wfixicon or simply the proprties option. |
BAF
Member #2,981
December 2002
![]() |
Wfixicon will work with datafiles. But the icon has to be compiled in as a resource, you can't just have it reference the datafile for the icon. Unless you make a shortcut, but if you want the exe itself to bear the icon, using a resource file is your only option, and wfixicon makes it easier. |
Timorg
Member #2,028
March 2002
|
Not really the solution you want, but I have code from an old project that can generate icons on the fly, allowing you to convert a allegro bitmap to an icon, then use that. I need to clean it up, as the project is a mess, I am going to clean it up now, which will take a little while. When its together I will post it here. ____________________________________________________________________________________________ |
James Stanley
Member #7,275
May 2006
![]() |
I'm sure that if you look in the header file that fixicon gives you, it just has some text that is the icon. Load the text out of a datafile and you've pretty much done the same thing. |
Timorg
Member #2,028
March 2002
|
Here is a working of example of a bitmap that is converted to a HBITMAP, which is converted to a HICON which is then sent as a message to the window. (I am pretty sure when you SendMessage, it makes it own copy of the icon) There is a code::blocks project file, and a makefile in the archive to build the example. To use this all you have to do is: HBITMAP HBImage = convert_bitmap_to_hbitmap(image); HICON TEST = CreateIcon(HBImage, 1, 1); DeleteObject(HBImage); SendMessage( win_get_window(), (UINT) WM_SETICON, (WPARAM) ICON_SMALL, (LPARAM) TEST);
The code works, but I am sure it could be improved. One of the attached files is broken. I'm not sure which one, and you can't delete attachements, Just grab it from http://www.timorg.net/create_icon.zip It just occurred to me you might not have meant windows, but unix has "extern void *allegro_icon;" to do it ____________________________________________________________________________________________ |
BAF
Member #2,981
December 2002
![]() |
Quote: I'm sure that if you look in the header file that fixicon gives you, it just has some text that is the icon. Load the text out of a datafile and you've pretty much done the same thing. That is just the definition of the stuff in the resource file. You likely don't even need to touch it. Also, Timorg's method changes the icon of the running program, wfixicon will keep that icon when the program is not running. |
Timorg
Member #2,028
March 2002
|
I guess it depends on what they mean by 'program icon', I assumed they meant window icon. You know what they say when you assume something, makes and ass out of you and me. ____________________________________________________________________________________________ |
James Stanley
Member #7,275
May 2006
![]() |
Quote: That is just the definition of the stuff in the resource file Wanna bet?
That doesn't look much like a definition of a resource file... |
Timorg
Member #2,028
March 2002
|
Cute icon, had to write a program to view it (which is attached), from the text version it almost looked like the figures were having sex. ____________________________________________________________________________________________ |
James Stanley
Member #7,275
May 2006
![]() |
You don't need to write a program to view it... |
Timorg
Member #2,028
March 2002
|
That doesn't work on windows, hence the program, if I ran linux, I could have done that. ____________________________________________________________________________________________ |
James Stanley
Member #7,275
May 2006
![]() |
Oh, sorry. I forgot. Windows must be deliberately complicated. |
BAF
Member #2,981
December 2002
![]() |
Quote: Wanna bet? Yes. Now look in the resource file. I bet you it references the icon as well. |
Timorg
Member #2,028
March 2002
|
Assuming you have a icon, to set it as the window icon SendMessage( win_get_window(), (UINT) WM_SETICON, (WPARAM) ICON_SMALL, (LPARAM) icon); doesn't seem all that complicated to me. I guess it might seem complicated that you need to ask the application to set the icon to something, rather than just setting it, but it adds thread safety. Windows uses a different format for icons, that what allegro uses for bitmaps, so they need converting. I don't see that microsoft was being "deliberately complicated" when they don't use bitmaps for icons. Icons and cursors are in the same format, how do you propose they store the x and y for the hotspot of the cursor in a bitmap. Or should they have 2 different formats, one for icons and one for cursors, and how can you store multiple sized versions of an icon in a bitmap? (yes I am aware I am feeding a troll ____________________________________________________________________________________________ |
BAF
Member #2,981
December 2002
![]() |
Also, Timorg, if you simply use it in the resource file, the exe will then have that icon, and Windows will show it for the window by default. |
James Stanley
Member #7,275
May 2006
![]() |
Quote: Yes. Now look in the resource file. I bet you it references the icon as well. There isn't a resource file. That header is all that there is. I had forgotten that Windows is more complicated than it need be. |
Timorg
Member #2,028
March 2002
|
I use a default rc for for all my programs, so they all have the same icon. But there are other cases where you might like to use a custom icon for the window. If your game is modded by providing a datafile that has the levels and art and everything in it, when you load the datafile, you might like to load a mods icon to the window icon (Which is possibly what the OP wanted). Or taking gimps example, a copy of the current bitmap is used for the editors window icon. Or you want to use allegro to generate tray icons, that change to show what is happening while your program is minimized. As long as your not expecting it to change your programs executable icon, this can be really useful. ____________________________________________________________________________________________ |
BAF
Member #2,981
December 2002
![]() |
Well, wfixicon doesn't work on Linux. But it most definitely gives you a resource file, and if you tell it to it will even compile it for you. |
|