Пример #1
0
        /// <summary>
        /// The meat and potatoes of the get icon functions above. Gets an icon based on the
        /// given path and flags. Will attempt to fetch icons from Image Lists if they use
        /// those (eg: .lnk/.url files).
        /// </summary>
        /// <param name="path">The path to get the icon for.</param>
        /// <param name="flags">A bitfield representing flags to pass to
        /// <see cref="Trampolines.ShellGetFileInfo(string, FileAttributes, uint)"/></param>
        /// <param name="attribs">FileAttributes of the given path.</param>
        /// <returns>The requested icon.</returns>
        private static SDIcon GetIcon(string path, uint flags, FileAttributes attribs = 0)
        {
            (SHFILEINFO info, IntPtr list) = Trampolines.ShellGetFileInfo(path, attribs, flags);

            SDIcon icon = null;

            if (info.hIcon != IntPtr.Zero)
            {
                icon = SDIcon.FromHandle(info.hIcon).Clone() as SDIcon;
                DestroyIcon(info.hIcon);
                return(icon);
            }
            else if (list != IntPtr.Zero && info.iIcon != IntPtr.Zero)
            {
                icon = Trampolines.GetIconFromList(list, info.iIcon.ToInt32());
            }

            return(icon);
        }