changing the .ico of exe

Started by
11 comments, last by Paulius Maruska 16 years, 10 months ago
Hello, I am using Microsoft Visual C++ 2005 Express Edition and SDL for my program and I want to change its icon. SDL_WM_SetIcon seems to only change the icon at the taskbar or something.
Advertisement
You need to embed an icon resource with the correct ID into your executable. You will need to use the resource compiler to do this. Luckily, DevStudio can do a lot of this for you. Use the Project->Add Resource menu item (or something along those lines), select the icon resource type, create the icon and it should all just work next time you compile the project.

Skizz
Hello LordKass

Well i am not to sure about SDL have not used it in a long time however there are way you can change that.

If you created your own window it is easy enough to do your just have to change a few minor things when you register the class but useing sdl if im not mistaken you do not create the window yourself so.

if you have access to the windows handle however this can still be done.

a windows handle is define as so HWND HandlesName.

if you have access the the instance do this
HICON hicon = LoadIcon(hInstance,"The Icon file");
else use this line it may however generate a warning

HICON hicon = LoadIcon((HINSTANCE) GetWindowLong(WindowsHandle,GWL_HINSTANCE),"The Icon file");

SendMessage(WindowsHandle,WM_SETICON,ICON_BIG,(LPARAM)(HICON) hicon);
SendMessage(WindowsHandle,WM_SETICON,ICON_SMALL,(LPARAM)(HICON) hicon);

Do this only after the windows been created.
im not sure if this helps because you may not have access to the windows handle but hopefuly it does.


Edit: Note if you do not wish to use a resource editor for any reason this method will allow you to load from file.
Ps. do rate user that help you it lets them know tis appreceated!
If you want to change the icon of your exe file in the explorer - you will have to write a simple resource file for that.

Unfortunately, Visual C++ 2005 Express Edition doesn't include the resource editor, so you will not be able to edit the resource file visually. However, it is very easy to write it by hand.

The main rule, that you should know, is that the program icon is the FIRST icon in the executables resources. You can have as many icons as want, but the first one will be the one that is shown in explorer.

So, the simplest possible resource file is this:
1 ICON "my_icon.ico"

Note, that the icon file name (the thing inside quotes) can be anything you want.

Now, to make it work - create a file with the *.rc extension (you can use Notepad for that) and paste that line in this RC file. Now, place the rc file into your projects source directory. In VC++ Solution Explorer, right-click on your project and choose to add the existing source file - select the RC file. You won't be able to edit the RC file in the VC++, but the file will be build automatically, and the icon will be shown correctly in explorer.

If you have some free time, you can read about the Windows resource files and the resource compiler here.
Hmm i did not though about going about doing it that way. Well ill have to remmber that next time i see a resource question.

just wanted to say that was a great answer Paulius Maruska

:: nods nods :: and more practical then mine i over thought it yup ...
Thanks everyone. The only thing i need now is changing the icon at the top left portion of the window.
Quote:Original post by LordKass
Thanks everyone. The only thing i need now is changing the icon at the top left portion of the window.


That's the same icon as the application icon. If you get the exe to appear with your icon in explorer then the icon in the top left should change as well. If it doesn't you may need to add an additional icon size to the ico file (the ico files contain several images of different sizes).

Skizz
Quote:Original post by Skizz
Quote:Original post by LordKass
Thanks everyone. The only thing i need now is changing the icon at the top left portion of the window.


That's the same icon as the application icon. If you get the exe to appear with your icon in explorer then the icon in the top left should change as well. If it doesn't you may need to add an additional icon size to the ico file (the ico files contain several images of different sizes).

Skizz


How to add an additional icon size to the ico file then?

Quote:Original post by LordKass
Quote:Original post by Skizz
Quote:Original post by LordKass
Thanks everyone. The only thing i need now is changing the icon at the top left portion of the window.


That's the same icon as the application icon. If you get the exe to appear with your icon in explorer then the icon in the top left should change as well. If it doesn't you may need to add an additional icon size to the ico file (the ico files contain several images of different sizes).

Skizz


How to add an additional icon size to the ico file then?


How about an Icon Editor? Do a web search for that term and you'll get loads of apps that allow you to edit icons.

Skizz
Quote:Original post by Jouei
HICON hicon = LoadIcon((HINSTANCE) GetWindowLong(WindowsHandle,GWL_HINSTANCE),"The Icon file");


That's a really kludgy way of getting the app instance. The better way is to call GetModuleHandle(NULL).

This topic is closed to new replies.

Advertisement