[英]How can I get the icon from the executable file only having an instance of it's Process in C#
我可以从进程中获取可执行文件位置,如何从文件中获取图标?
也许使用windows api LoadIcon()。 我想知道是否有.NET方式......
Icon ico = Icon.ExtractAssociatedIcon(theProcess.MainModule.FileName);
这是来自控制台应用程序实现的示例。
using System;
using System.Drawing; //For Icon
using System.Reflection; //For Assembly
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
try
{
//Gets the icon associated with the currently executing assembly
//(or pass a different file path and name for a different executable)
Icon appIcon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
}
catch(ArgumentException ae)
{
//handle
}
}
}
}
使用ExtractIconEx (和此处 )p / invoke。 您可以从任何DLL或exe中提取小图标和大图标。 Shell32.dll本身有200多个图标,对标准Windows应用程序非常有用。 您只需先弄清楚所需图标的索引是什么。
编辑:我做了快速SO搜索,发现了这一点 。 索引0图标是应用程序图标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.