0

我希望能够从其句柄中获取程序图标(从带有 EnumWindow/FindWindow 的 User32.dll 获取),我知道ExtractAssociatedIcon但我相信这可以从文件而不是句柄中工作。这个问题可能是如何将 Handle 转换为要转换为 Icon 的文件位置。

我的意图是将此代码移植到 JavaScript,node-ffi以便在node-hide中使用,我的 npm 模块用于隐藏和显示 Windows 程序。使用 DLL 将是最简单的,但 C/C# 解决方案将起作用。只是求指导,谢谢。

4

1 回答 1

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);
于 2016-06-27T06:18:11.677 回答