public static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbfileInfo, SHGFI uFlags);
/// <summary> /// 获取文件的默认图标,可以只是文件名,甚至只是文件的扩展名(.*); /// 如果想获得.ICO文件所表示的图标,则必须是文件的完整路径。 /// </summary> /// <param name="fileName">文件名</param> /// <param name="largeIcon">是否大图标</param> public static Icon GetFileIcon(string fileName, bool largeIcon) { SHFILEINFO info = new SHFILEINFO(); int cbFileInfo = Marshal.SizeOf(info); SHGFI flags; if (largeIcon) { flags = SHGFI.Icon | SHGFI.LargeIcon | SHGFI.UseFileAttributes; } else { flags = SHGFI.Icon | SHGFI.SmallIcon | SHGFI.UseFileAttributes; } NativeMethods.SHGetFileInfo(fileName, 256, out info, (uint)cbFileInfo, flags); return Icon.FromHandle(info.hIcon); }