Utils/ExeIconUtils.cs

(完整代码) 1KB

using AppManager.Config;
using System;
using System.Collections.Generic;
using System.Drawing;

namespace AppManager.Utils {
    class ExeIconUtils {
        /// <summary>
        /// 获取exe文件中的图标
        /// </summary>
        /// <param name="exePath"></param>
        /// <returns></returns>
        public static List<Image> GetIconImage(string exePath) {
            List<Image> imageList = new List<Image>();
            //第一步:获取程序中的图标数
            int iconCount = DllUtils.ExtractIconEx(exePath, -1, null, null, 0);

            //第二步:创建存放大/小图标的空间
            var largeIcons = new IntPtr[iconCount];
            var smallIcons = new IntPtr[iconCount];

            //第三步:抽取所有的大小图标保存到largeIcons和smallIcons中

            DllUtils.ExtractIconEx(exePath, 0, largeIcons, smallIcons, iconCount);

            //第四步:显示抽取的图标(推荐使用imageList和listview搭配显示)

            for (int i = 0; i < iconCount; i++) {
                var icon = System.Drawing.Icon.FromHandle(largeIcons[i]);
                imageList.Add(icon.ToBitmap());
                icon.Dispose();
                // 销毁图标
                DllUtils.DestroyIcon(largeIcons[i]);
                // 向控件发送关闭指令
                DllUtils.SendMessage(largeIcons[i], WinApi.WM_CLOSE, 0, string.Empty);
            }

            return imageList;
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。