BelhardTraining.LessonMultithreading.IconTools.GetIconForFile C# (CSharp) Метод

GetIconForFile() публичный статический Метод

Returns an icon representation of the specified file.
public static GetIconForFile ( string filename, ShellIconSize size ) : Icon
filename string The path to the file.
size ShellIconSize The desired size of the icon.
Результат System.Drawing.Icon
        public static Icon GetIconForFile(string filename, ShellIconSize size)
        {
            SHFILEINFO shinfo = new SHFILEINFO();
            NativeMethods.SHGetFileInfo(filename, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), size);

            Icon icon = null;

            if (shinfo.hIcon.ToInt32() != 0)
            {
                // create the icon from the native handle and make a managed copy of it
                icon = (Icon)Icon.FromHandle(shinfo.hIcon).Clone();

                // release the native handle
                NativeMethods.DestroyIcon(shinfo.hIcon);
            }

            return icon;
        }