2016-06-27 74 views
0

我希望能夠從其句柄中獲取程序圖標(從EnumWindow/FindWindow中從User32.dll獲取),我知道ExtractAssociatedIcon,但我相信這是從文件而不是從一個手柄。這個問題可能是如何將句柄轉換爲文件位置以轉換爲圖標。從句柄中獲取程序的圖標

我的意圖是通過node-ffi將此代碼移植到JavaScript中,用於node-hide,我的npm模塊用於隱藏和顯示Windows程序。使用DLL將是最簡單的,但C/C#解決方案將起作用。我只是要求指導,謝謝。

回答

0

在C#中,您可以使用shell32.dll函數。

代碼:

// Required namespaces. 
using System; 
using System.Drawing; 
using System.Reflection; 
using System.Runtime.InteropServices; 

// Import the function. 
[DllImport("shell32.dll", EntryPoint="ExtractAssociatedIcon")] 
public static extern IntPtr ExtractAssociatedIcon(IntPtr hInst, string lpIconPath, out ushort lpiIcon); 

// Now get the icon. 
ushort uicon; 
IntPtr handle = ExtractAssociatedIcon(this.Handle, Assembly.GetExecutingAssembly().Location, out uicon); 
Icon ico = Icon.FromHandle(handle);