2016-06-27 42 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);