2010-01-26 76 views
4

我正在尋找在.Net中的可執行文件的應用程序圖標。我怎樣才能做到這一點?我想我將不得不查詢其資源,一些如何,但我可以接受任何一般情況下的解決方案。如何在.Net中獲得可執行文件的圖標?

+0

這是從另一個應用 – ChrisF 2010-01-26 18:52:02

+0

是的。我想通過它從我正在寫的應用程序的路徑檢索可執行文件的圖標。 – 2010-01-26 18:53:36

回答

3

從硬路徑:

Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(filePath); 

從資源DLL:

// Process handle 
IntPtr processHandle = System.Diagnostics.Process.GetCurrentProcess().Handle; 

// DLL path 
string DLLPath = Path.Combine(Environment.SystemDirectory, "shell32.dll"); 

// Open folder icon index 
int iconIndex   = 4; 

// Extract icon 
System.IntPtr oPtr = ExtractIcon(processHandle, DLLPath, iconIndex); 

Icon oIcon = Icon.FromHandle(oPtr); 

來源:

C# Extract icons and system icons

1

以下應該工作。它還會爲其他文件類型(即.txt的白紙)拉取圖標,儘管它不會拉取嵌入的縮略圖(因爲這些文件是通過shell擴展注入的)。

icon = Icon.ExtractAssociatedIcon(filename);

相關問題