tags:

views:

221

answers:

1

Some Windows programs can use different icons for different files with the same extension.

Example

  • .sln can show a different icon depending on what version of Visual Studio the solution was made in (actually, determined by the version number in the top line in the .sln)
  • Photoshop .psd files have icons with a thumbnail of the image
  • A .url shortcut file has the page's favicon if opened in, or saved from, Internet Explorer

I'm guessing it must be custom to that computer only. On a box without Visual Studio installed, .sln files just have the default 'I don't know this program' icon. Is there something that needs to be changed in the registry?

How can I do this? I'd like to have the option of associating custom icons with files to my own programs.

[Edit] I really with I could do this in managed code. It's possible (<SDK v1.1>\Samples\Technologies\Interop\Applications\ShellCmd) but it also appears to be potentially dangerous and the wrong tool for the job in practice: http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/1428326d-7950-42b4-ad94-8e962124043e/. I really hoped MS would have a good managed API for this kind of stuff by now.

+1  A: 

Check out this C++ code on CodeProject: essentially, you write a COM handler and register it for your extension. Be aware that you can mess up the Explorer process pretty badly if you leak resources in icon handlers or shell extensions... C++ may be a challenge, but I wouldn't recommend doing this in C# or Java for reasons of memory consumption (a separate copy of the framework code for each extension/handler!).

Pontus Gagge
Great link and good warning about .NET/Java. I've never coded in C++ before. Is this beyond my skill level unless I learn C++?
Dinah
You can implement COM interfaces in .NET pretty easily, but the Explorer process will get bloated. It depends on what you want to achieve... but a small memory footprint is a definite plus for plugins!
Pontus Gagge
Both C++ and COM at one go is pretty heavy duty programming: not impossible by any means, but plenty of things can trip you up, not least leakages.
Pontus Gagge
But if you're doing it for fun, by all means try a .NET solution. I'd give some thought to testing it out on a virtual machine first, though!
Pontus Gagge