/// /// 依据文件名读取图标,若指定文件不存在,则返回空值。 /// /// /// public static Icon GetIcon(string fileName) { if (fileName == null || fileName.Equals(string.Empty)) return null; if (!File.Exists(fileName)) return null; SHFILEINFO shinfo = new SHFILEINFO(); //Use this to get the small Icon Win32.SHGetFileInfo(fileName, 256, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON); //The icon is returned in the hIcon member of the shinfo struct System.Drawing.Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon); return myIcon; }
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);