views:

188

answers:

3

I have both InDesign CS2 and CS3 installed. Both use files with .indd extension. How does Windows know which icon to use? It uses correct icons i.e. CS2 files have cs2 icon and CS3 files have CS3 icon.

How does Windows know how to do this?

And how can I extract or use this version-detection system in my programs?

Edit:

Thank you for your shell-extension-icon-handler answers. Something new to me. But is there any way I could connect to IconHandler that InDesign provides and use it to detect version of the InDesign file?

+3  A: 

You need to write an Icon Handler shell extension. See the MSDN documentation for IExtractIcon. The basic mechanism is that you create a shell extension and register the icon handler for the file type you want (look in HKEY_CLASSES_ROOT/.indd) and then the shell loads your handler, passes the file information and requests an icon in return. There's also the IExtractImage method if you want to provide a thumbnail bitmap rather than just an icon.

Note that you need to be especially careful writing shell extension handlers as any memory leaks or crashes can nuke the explorer and any other applications that display a file open/save dialog.

the_mandrill
Ok you answered first part of my question. The other part is probably impossible.
Kugel
+1  A: 

It almost certainly installs a shell icon extension handler. Writing your own and knowing how to detect the version in a file format that isn't documented well or at all is quite tricky.

Hans Passant
+1  A: 

For some files it's HKEY_CLASSES_ROOT\<file extension here>\DefaultIcon registry entry, but most files map to a more friendly name, e.g. .pdf\(Default) -> AcroExch.Document (if Adobe Reader is installed).

In that case you have to go along the registry to AcroExch.Document and see that either

  • DefaultIcon is right there or
  • AcroExch.Document\CLSID\(Default) is some GUID. Then, follow HKEY_CLASSES_ROOT\CLSID\<insert that guid here> and you'll notice that this key contains DefaultIcon

... and DefaultIcon is where the icon is loaded from.

Hope that was clear enough ;). I don't know about your special case but there should be a distinction in the registry.

AndiDog
That's the case for a fixed icon, but the OP was asking about how to switch the icon type programmatically when you have two versions of a file but with the same extension. +1 though for mentioning about having to do a second level of indirection on the GUID
the_mandrill