views:

270

answers:

3

I have application that produces files. I would like to connect those files with application so that double-click on file launches my application.

Everything works properly except for annoyance that icon looks same like icon of my application. I would like to have one icon for application and one icon for it's documents.

DefaultIcon value in registry requires "app.exe,1" syntax where 1 is icon index. It seems that .NET resources are not Win32 resources.

I tried following but without success:

  1. Selecting "Embedded Resource" as file's build action.
  2. Adding icon to resource file.

Only thing that worked is having icon file separated from executable and pointing to it. However, that seems to me like surrender.

Any ideas how to solve this?

+3  A: 

Have you tried setting 2 as the icon index?

EDIT: I found a way but you have to do it again for every new build.

  1. Open the .exe file in Visual Studio (File -> Open File)
  2. Right click the icon folder and select Add resource
  3. Click the button Import
  4. Select your .ico file
  5. You might have to mess with the icon numbers, I think the lowest number (example 101) will be the application's icon
  6. Remember the new icon number and set it as the index

EDIT 2: Try this article: http://www.codeproject.com/KB/dotnet/embedmultipleiconsdotnet.aspx

ZippyV
Yes, I tried quite a few numbers. Only one that returns anything is 32512. And that is my application icon. No number will return icon for document.
Josip Medved
That does work, but it also invalidates strong-name.
Josip Medved
A: 

DefaultIcon will also accept a path to a valid .ico file as an Icon.

Factor Mystic
That works, as I pointed in my question, but it doesn't seem right.
Josip Medved
A: 

You have to make sure that you have Win32 icons in your project not just .net icons. I HOPE that someone points out an easy way to do this, but in the mean time, here goes...

Compile your assembly, then from Visual Studio select "File -> Open -> Open File", open the compiled assembly. Add the icon you want to use for documents and set its ID to something above the one in use for your app. Save the assembly. Now you have Win32 resources available.

-- Edit --
After editing his post ZippyV appears to have a very good answer.

Brad Bruce