在WPF EXE嵌入多个图标 [英] Embed multiple icons in WPF EXE
问题描述
我有一个WPF组件,其中我想嵌入五个图标与我的应用程序关联的文件类型不同。
我如何嵌入这些图标进入我的EXE?
I have a WPF assembly in which I would like to embed five icons for different filetypes associated with my application. How can I embed these icons into my EXE?
@smoore @Groky @ChrisF,谢谢。
不幸的是,这不是我问。我看到我的问题是相当含糊0_°。让我改一下这个问题:
@smoore @Groky @ChrisF, thank you. Unfortunately, this is not what I asked. I see that my question was quite vague 0_°. Let me rephrase the question:
我的图标,说 Application.ico
, Document.ico
等在我的WPF项目资源。我访问在大多数情况下,这些图标,以下内容:
I have icons, say Application.ico
, Document.ico
, etc. as resources in my WPF projects. I access these icons in most cases with the following:
<Image Source="/MyAssembly;component/Resources/Icons/Application.ico" />
这每一次的作品。我知道这一点。
That works every single time. I know that.
什么,我的问题是关于是我如何使用相同的图标从Windows资源管理器在注册表文件关联。我希望能够像一个路径来访问的图标:
What my question is about is how can I use the same icons from Windows Explorer for file associations in the registry. I want to be able to access the icons with a path like:
C:\Program Files\MyApp\MyApp.exe,1
像如何与文件类型在 HKEY_CLASSES_ROOT <相关的图标/ code>。
Like in how icons are associated with filetypes in HKEY_CLASSES_ROOT
.
据我所知,我应该使用一个资源文件( .RC
),编译我的EXE合并。沿着线的东西:
AFAIK, I should use a resource file (.rc
), compile and merge it with my EXE. Something along the lines of:
101 RT_ICON Application.ico
102 RT_ICON Document.ico
// etc...
这是在WPF的正确方法?是否有替代品,特别是因为这种方法似乎导致了的程序集的版本从擦除我的的AssemblyInfo.cs
。我还准备有写在资源,而不是组装的信息的版本信息。
Is this the right way in WPF? Is there an alternative, especially since this method seems to lead to the erasure of the assembly version from my AssemblyInfo.cs
. I am still prepared to have to write the versioning info in the resource instead of the assembly's info.
推荐答案
我发现的一个解决方案的!它并不完美,但它确实我想要的!正如我使用很长的斯堪的纳维亚的夜晚找到了解决方案,我觉得我必须在这里分享
I have found one solution! It's not perfect but it does what I want! As I used very long Scandinavian nights to find the solution, I feel that I have to share it here.
下面是我所做的:
1)写一个哑终端C#应用程序。
1) Wrote a dumb console C# app.
class ResTest {
static void Main() {
System.Console.WriteLine("Hello World!");
}
}
2)有没有一个简单的 CSC restest.cs
来测试我的代码工作。
2) Did a simple csc restest.cs
to test that my code worked.
3)打开记事本,写在我被称为一个文件下面的 App.rc
。
3) Opened Notepad and wrote the following in a file I dubbed App.rc
.
101 ICON "Application.ico"
102 ICON "Document.ico"
103 ICON "Help.ico"
4)冉 RC / v App.rc
的的资源编译器。一个新的文件, App.res
出现了。
4) Ran rc /v App.rc
, the Resource Compiler. A new file, App.res
had appeared.
5)重新运行 CSC
但这一次:
5) Reran csc
but this time:
csc /win32res:App.res restest.cs
6) restest.exe
现在已经与101的ID的图标和我能找到在Axialis IconWorkshop其他两个图标。
6) restest.exe
had now the icon with the ID of 101 and I could find the two other icons in Axialis IconWorkshop.
现在,我发现我的集信息(版本,产品名称,等等等等的等等)已经不见了。我用Google搜索 VS_VERSION_INFO
,来到约MSDN的有关VERSIONINFO结构在RC文件中定义了我所需要的属性的文章。
Now, I noticed that my assembly information (version, product name, blah blah blah) had disappeared. I googled VS_VERSION_INFO
and came about MSDN's article about the VERSIONINFO structure which in RC files defines the attributes I need.
我宁愿更多的'自动'的方法,但我必须做什么,我可以使用C#Express和Windows Vista中SDK
I would have preferred a more 'automated' method, but I must do what I can using the C# Express and the Windows Vista SDK.
- 希望你可以使用这...
-- Hope that you can use this...
这篇关于在WPF EXE嵌入多个图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!