3.01.2013

adding an icon to a C++ project with Visual Studio Express 2012

I wrote a simple application to perform a left mouse click after a certain amount of time elapsed.  Its pretty simple.  Took me maybe a half hour to code it up while wading though MSDN.

It took me at least 3 times as long to add an icon to my project.  Here's how I did it.

First, I created a .png icon.  This is no good, we need an .ico.  Fortunately, there is an awesome website that converts images to .icos:

http://www.icoconverter.com/

I had the best luck with All Sizes and 256 colors.

Next I needed to manually create a resource script for my project.  Real (non-free) versions of Visual Studio do this for you automatically.  Simply use your favorite text editor (mine is gvim) and create a text file that looks something like the following:

programIcon ICON "icon.ico"

I named my script "resources.script" and placed it in the same directory as my icon.ico file.

Next you need to manually run rc.exe.  This should get installed with Visual Studio, mine was located here:

C:\Program Files (x86)\Windows Kits\8.0\bin\x86

I added this location to my path and then opened a shell to the location of my resources.script and ran:

rc.exe resources.script

This produced a "resources.res" file.  I imported this into my Visual Studio project by right clicking the "resources" folder under my project under my solution and "Add Existing".  Then I rebuilt my solution and voila!  icon!


1 comment: