【问题标题】:Getting A Program's Icon From Handle从句柄获取程序的图标
【发布时间】:2016-06-27 05:24:24
【问题描述】:

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

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

【问题讨论】:

    标签: javascript c# node.js windows node-ffi


    【解决方案1】:

    在 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-26
      • 1970-01-01
      • 1970-01-01
      • 2014-05-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      相关资源
      最近更新 更多