In the previous post, Exploring the GrabAPicture Application (Part 3), you completed configuring the forms for this application. This post adds an icon to the application. Icons can be a problem because there is so much conflicting documentation about them. Some people actually go so far as to say you must create your icon in an external environment because Visual Studio doesn’t support 32-bit icon development.
One of the things I decided to experiment with is the minimum requirements for icons in Windows 7—the most demanding icon environment to date. Here are my conclusions:
- You can development icons in Visual Studio without any problem.
- Icons can be 4-bit graphics, despite what you have read elsewhere.
- To see the icon in all Internet Explorer views, you must supply the following sizes:16×16, 32×32, 48×48, and 256×256.
- All of the icons must appear in a separate file with a .ICO extension.
Anything else you might have heard is simply wrong. I created the icons for this example using Visual Studio with 4-bit graphics. They show up just fine in Internet Explorer, the Start Menu, the Taskbar, and everywhere else I’ve tried. I’m not much of an artist, but these icons will do just fine.
Now that you have an icon to use, you need to perform a number of tasks to see it.
- Save the icon to the application’s development folder on disk.
- Look for the icon in Solution Explorer. If you don’t see it, right click the project entry and choose Add | Existing Item from the context menu. Locate the .ICO file in the Add Existing Item dialog box and click Add.
- Select the icon in Solution Explorer and choose Embedded Resource in the Build Action property of the Properties window. Ensure that the Copy to Output Directory property is set to Do Not Copy.
- Select each form in turn and set its Icon property to the .ICO file you created. You’ll see the icon appear in the usual location in the upper left corner of the form.
- Right click the project entry in Solution Explorer and choose Properties from the context menu. You’ll see the project’s Property window open.
- Select the Application tab. In the application tab, set the Icon property to the .ICO file you created earlier. You’ll see the icon appear on the page as shown here.
At this point, you can build your application and see the results. Unfortunately, Windows may not cooperate with you. You may see the original application icon. It seems that Microsoft decided to create an icon cache to make application performance faster. This cache causes problems because it stores your old icon, rather than the one you just created. The following steps will help you see your new icon (these steps will work in Windows 7 and should also work with Vista—Windows XP developers will have to modify the steps to meet their needs).
- Close all copies of Internet Explorer and Windows Explorer.
- Right click the Desktop and choose Personalize from the context menu. You see the Personalization window.
- Set the theme to Windows 7 Basic. Windows changes the theme for you. Using this theme gives you access to an important feature.
- Click Window Color near the bottom of the Personalization window. You see the Window Color and Appearance dialog box shown here.
- Select Icon in the Item field.
- Type 33 in the Size field and click Apply. This step forces Windows to clear the cache. However, the icons are now at an unusable size.
- Type 32 in the Size field and click OK. You’ve set the icon size back to its original size.
At this point, you should see your new icon used everywhere the application’s executable appears. Open a copy of Windows Explorer to see for yourself. If you still don’t see the new icon, close all copies of Internet Explorer and Windows Explorer manually and reboot the system. Let me know if you have any trouble with this process at John@JohnMuellerBooks.com. You can see the next post in this series at Exploring the GrabAPicture Application (Part 5).