How to add an icon to your windows application executable in Microsoft Visual C++ Express Edition

Adding an icon to your ".exe"
In this short tutorial I'll show you how to add an icon to the executable file, so it's seen on the Windows' explorer application.
How? Easy as pie.

Open the notepad application (Start → Run... → "notepad" → OK)
Write this line:

IDI_APP     ICON       "my_icon.ico"
Being "my_icon.ico" the name of your icon file.
Save the file as "resource.rc" to your project's directory (the icon file should be in the same directory too)
Then go to your project view in MSVC, and right click on the "Resource Files" folder, click "Add → Existing item..." and then select the "resource.rc" file.


This works for Microsoft Visual C++ Express Edition version 2008. But I believe it should also work for the 2005 version.

You can add all sorts of resources by hand this way, like bitmaps using the "BITMAP" keyword instead of "ICON" and then access them during run time (Clue: See WINAPI's LoadResource() and FindResource() )
For more information on resources, visit this article from the MSDN.

And how do I make an icon anyway?

You can use the awesome and free IcoFX application to author icons.
After drawing your icon, you must create multiple icon sizes so Windows can use them depending the context (e.g. in report view, in icon view and in the big thumbnail view also).

This is really easy, as IcoFX does it automatically for you.
Click on the Icon menu → Create Windows Icon From Image... → OK. and you're done!
You must save this file as it creates a new one keeping the original safe from modifications.



I hope you liked this tutorial
Good luck!
-Martín

0 comments: