示例#1
0
 internal static Icon GetFileIcon(string filePath, bool large)
 {
     try
     {
         SHGFI         shgfi;
         Win32FileInfo structure = new Win32FileInfo(true);
         int           num       = Marshal.SizeOf(structure);
         if (large)
         {
             shgfi = SHGFI.Icon | SHGFI.UseFileAttributes;
         }
         else
         {
             shgfi = SHGFI.Icon | SHGFI.UseFileAttributes | SHGFI.SmallIcon;
         }
         Win32FileInfo.SHGetFileInfo(filePath, 0x100, out structure, (uint)num, shgfi);
         return(Icon.FromHandle(structure.hIcon));
     }
     catch
     {
         return(null);
     }
 }
 internal static extern int SHGetFileInfo(string pszPath, int dwFileAttributes, out Win32FileInfo psfi, uint cbfileInfo, SHGFI uFlags);