Custom Executable Icon

Could someone please exsplain to me how to change the default executable file icon, I read that a resource file should be used but I can not see how to achieve the result im looking for. (I'm using visual studio exspress.)

As you no doubt already know, the express addition of Visual Studio does not include the wizard or other tools for resource or icon creation or editing. But there are third party tools, like ResEdit, for resource editing (including a basic icon editor), and aaICO, for icon editing (see below).

If you created a Win32 GUI app using the New Project wizard, then you should aready have a resource file (.rc), resource header (resource.h) and one or two icon files (.ico) added to your project. So you just need to edit the icons.

Creating icon

If you do not have any .ico files, you will need to:
- create a new one
- copy an existing one from somewhere and modify it
- obtain one from a free icon site or elsewhere

If you don't already have an icon editor, then check out aaIco Icon Editor.

Creating resource file

If you do not already have an .rc file (and its associated resource header) you need to either:
- create one manually
- create one by using the New Project to create a GUI app, and then copy the .rc file, resources.h and the .ico files (there should be one with the same name as the project and another called 'small')
- create one using a third party tool (e.g. reedit.exe)

Creating resource manually...

If you go the manual route, you need to create two text files:
- By convention, the .rc file takes the same name as the project. e.g. for my_project you will have my_project.vcproj, to the .rc file should be my_project.rc (it doesn't have to use this name, but it's what's normall used)
- And the resource header is usually called resource.h

If you just want to add an icon, all you need in them are (after adjusted the project name):

Notes:
- following another convention, I have put my .ico file in a red subfolder of the project folder. While this is optional, it does help when your program uses a lot of resources.
- the app's main icon is often called after the project. But I have also seen them called app.ico, main.ico, etc -- or even what it is (e.g. smiley.ico for an icon of a smiley.)
- the resource id value of 128 is the same value as is used by the Visual Studio's resource wizard when creating a new resource.

Copying existing resource...

If you copy the files from an existing (GUI) project, you will need to not just rename the files, but edit them so they refer to the new project rather than the old one.

Creating resource using third party tool...

If you use (e.g.) resedit, it will create the .rc and resource header file for you.

You can also use it to create and edit the required icon file (once you've create a new resedit project.)

Ading resource file to project...

In all cases, you will then need to add the .rc file to the project, so it is compiled and linked in.

You can also add the resource heeder and the .ico file, for completeness. By convention, the .ico is put in a "Resource File" filter (right click on project in Solution Explorer and choose "Add" > "New Filter", etc.)

And finally...

Finally, if you are writing a GUI app, you need to ensure that your icon, rather than a stock system icon, is used when registering your application's main window class. (Look for the call to RegisterClassEx and confirm that the hIcon member of the WNDCLASSEX is set to the handle for your new icon, e.g. (where wcex is a variable of type WNDCLASSEX)

And similarly for the hIconSm member (if you also have a separate small icon, use the same one for both.)

Note that if an app has a dialog for its main window, you don''t get the chance to specify which icon you want when registering the window class because the dialog window class already exists. You could register a copy of the class, with a new icon, but it is easier to use the WM_SETICON to change the icon used by the dialog window to the one you want. The message is sent in the WM_INITDIALOG message handler of your dialog, e.g. (where hIcon is your icon handle, obtained using the LoadImage function)

ResEdit is a resource editor for Windows programs. The original purpose was to help C++ developers to create resource scripts. Now it can also be used to modify any resource in PE files (exe, dll, ...) and compiled resource scripts (res files).

aaICO - This is a Free Icon Editor that you will find very useful. If you like our software, please add a link to our site. This is a great free tool. The editor supports multiple resolutions, importing, exporting, various effects and much more.