Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Vista generate the icon for documents associated to my application?

Can I affect the process?
I have an application built in .NET 3.5 / VS2008. I have embedded multiple icons into the app with a win32 .res file. This is done in the Properties box for the Project in VS2008 - instead of specifying an .ico file, tick the box to specify a .res file. In the .res file you can have multiple icons. See here for what I mean.

Each icon includes a 256x256xRGB (PNG Cmopressed) "Vista grade" image, a 256x256x32bit image, and the usual cascade of 48x48, 32x32, and 16x16 images in various color combos. If I view the resulting exe in Explorer, I see the big beautiful 256x256 Vista images.

I can then associate a file extension to my app, using the right click > "Open With..." > Set Default Program clickstream in Vista's Explorer. But the icon displayed next to the document is then a small version of the app icon, overlayed on top of what looks like a white sheet of paper with a folded corner.

The result is that the original image is waaaay to small to be visible, when it is shown in "small icon" version. It looks terrible.

I know it is possible to completely omit the folded piece of paper, or at least to get a much larger image overlayed on it. The icon for a C# file, for example, has a folded sheet of paper, but the C# emblem is large and visible. How can I get this? The icon for .zip files when WinZip 12 is installed, is large and visible, and has no folded sheet of paper.

Is the icon-for-documents different than the icon-for-the-application? Is there something in my app that I have to do in order to register an Icon that Vista will use for documents associated to my app?

like image 520
Cheeso Avatar asked Feb 24 '09 07:02

Cheeso


1 Answers

The icons and file associations for file extensions are listed in the registry. More specifically, HKEY_CLASSES_ROOT\.ext entries contain the content type, perceived type and in the (Default) value is the actual association. For example, .cs files have default value of VisualStudio.cs.9.0 (I've got VS 2008). You can check the HKEY_CLASSES_ROOT\VisualStudio.cs.9.0 to see the actual icon, program and commands associated with this file type. In particular, the HKEY_CLASSES_ROOT\VisualStudio.cs.9.0\DefaultIcon is the entry that tells Explorer which icon to show for files of this type. It points to a binary and a resource ID in that binary.

When you associate a file type with a program through the right click -> Open With..., you don't specify a default icon, so Explorer takes the icon of your app and overlays it over a generic document icon.

The right approach would be to include as part of your setup the appropriate registry entries to associate the file type with your application and your icon. The exact registry values you need to include depend on the commands you want added to the context menu for that file type, but at the very least you want the Open command. In the case of .cs files, you can see that there is an entry HKEY_CLASSES_ROOT\VisualStudio.cs.9.0\Shell\Commands\Open with (Default) value containing the application to start when the Open command is invoked. (You can ignore the ddeexec part for now)

Keep in mind that the HKEY_CLASSES_ROOT is a mapped view of two registry branches: HKEY_CURRENT_USER\Software\Classes and HKEY_LOCAL_MACHINE\Software\Classes. If you want your file association to be for all users, you need to write to HKEY_LOCAL_MACHINE. Your setup needs to run as admin to do that. Otherwise, attempting to write to HKEY_CLASSES_ROOT will either fail with access denied or write to HKEY_CURRENT_USER and do the association only for the current user. (Which of the two exactly will happen depends on several things, like what the OS is, whether the user is admin but not elevated and so on)

You can read about all this in Customizing File Types (Files Associations) section on MSDN. In particular, File Types and Registering Programs with Client Programs would give you the basics of how exactly to do this.

like image 141
Franci Penov Avatar answered Nov 15 '22 03:11

Franci Penov