Registering file type and custom document icon in .NET

后端 未结 4 2073
余生分开走
余生分开走 2021-01-13 11:58

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 p

相关标签:
4条回答
  • 2021-01-13 12:10

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

    0 讨论(0)
  • 2021-01-13 12:10

    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.

    0 讨论(0)
  • 2021-01-13 12:20

    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

    0 讨论(0)
  • 2021-01-13 12:22

    If you are using the Wix toolset (http://www.wixtoolset.org) to install your application, you can get Wix to take care of the file type and document icon registration

    Here is my magic Wix incantation:

        <!-- Your executable -->
        <File 
            Id="MaAppExe" 
            Name="MyApp.exe" 
            Source="MyApp.exe" KeyPath="yes" >
        </File>
    
        <!-- your document icon -->
        <File 
            Id='IconMyAppDoc.ico' 
            Name='IconMyAppDoc.ico' 
            Source='$(var.MyApp.ProjectDir)\Resources\Images\Icons\docicon.ico' />
    
        <-- File Extension and associated document icon -->
        <ProgId 
            Id='MyApp.MyAppExtension' 
            Description='My App Data File' 
            Icon='IconMyAppDoc.ico'>
            <Extension 
                Id='MyApp' 
                ContentType='text/plain'>
                <Verb 
                    Id='open' 
                    Command='Open' 
                    TargetFile="MyAppExe" 
                    Argument='"%1"' />
             </Extension>
        </ProgId>
    </Component>
    
    0 讨论(0)
提交回复
热议问题