[英]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.