将多个图标(Win32-Resource)添加到 .NET-Application [英] Adding multiple Icons (Win32-Resource) to .NET-Application

查看:18
本文介绍了将多个图标(Win32-Resource)添加到 .NET-Application的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在项目属性中设置应用程序图标.如果您这样做,exe 将具有此图标而不是默认图标.这个图标是一个 win32 资源,也可以这样访问:

it is possible to set the Application-Icon in the Project Properties. If you do this the exe will have this icon instead of the default one. this icon is a win32-resource and can also be accessed like this:

我想要我的程序使用的文件类型的特殊图标.要关联文件类型图标,我可以在注册表中指定它(DefaultIcon"项中的MyProg.exe,1").

i want to have special icons for filetypes which are used by my program. to associate an filetype-icon i can specify it in the registry ("MyProg.exe,1" in the "DefaultIcon" Key).

那么如何向程序集中添加更多图标,以便我可以将其用于文件类型关联?

so how to ADD MORE icons to the assembly that i can use it for the filetype-association?

非常感谢

ps:它是一个 WPF 应用程序 (.NET 4.0)

ps: it is a WPF-Application (.NET 4.0)

推荐答案

Windows 对托管资源一无所知,您需要将非托管资源添加到您的可执行文件中.在 parapura 的屏幕截图中,您需要选择 Resource file 单选按钮.这需要一个 .res 文件,这是一个通过在 .rc 文件上运行 Windows SDK rc.exe 工具创建的二进制文件..rc 文件是一个简单的文本文件,其中包含资源语句,类似于:

Windows doesn't know anything about managed resources, you need to add unmanaged resources to your executable. In parapura's screenshot, you need to select the Resource file radio button. That requires a .res file, a binary file that's created by running the Windows SDK rc.exe tool on a .rc file. The .rc file is a simple text file that contains resource statements, similar to this:

1 ICON "mainicon.ico"
2 ICON "alternative1.ico"
3 ICON "alternative2.ico"
1 24 "app.manifest"

请务必将此文件保存到您的项目文件夹中,不要使用 utf-8 编码,最好使用记事本.使用 Project + Add New Item、Application Manifest File 创建所需的 app.manifest 文件.使用 Project + Add Existing Item 将此 .rc 文件添加到您的项目中.双击它并验证您是否可以看到图标和清单.右键单击顶部节点,添加资源,然后单击版本 + 新建.编辑版本信息,注意不再自动匹配AssemblyInfo.cs中的属性

Be sure to save this file into your project folder without utf-8 encoding, using Notepad is best. Create the required app.manifest file with Project + Add New Item, Application Manifest File. Add this .rc file to your project with Project + Add Existing Item. Double-click it and verify that you can see the icons and the manifest. Right-click the top node, Add Resource and click Version + New. Edit the version info, beware that it will no longer automatically match the attributes in AssemblyInfo.cs

您可以使用 Visual Studio 命令提示符将 .rc 文件编译为 .res 文件:

You can compile the .rc file into a .res file with the Visual Studio Command prompt:

rc /r something.rc

生成可在项目属性选项卡中使用的 .res 文件.这样做是一个预构建事件是可取的,但有点难以正确.这可能出错的方式有很多,祝你好运.

Which produces the .res file you can use in the project property tab. Doing this is a pre-build event is advisable but a bit hard to get right. The number of ways this can go wrong are numerous, good luck.

这篇关于将多个图标(Win32-Resource)添加到 .NET-Application的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆