Example #1
0
 public static System.Drawing.Icon GetFileIcon(string strPath, bool bSmall)
 {
     APIsStructs.SHFILEINFO info = new APIsStructs.SHFILEINFO(true);
     APIsEnums.ShellGetFileInformationFlags flags =
         APIsEnums.ShellGetFileInformationFlags.Icon |
         (File.Exists(strPath) ? 0 : APIsEnums.ShellGetFileInformationFlags.UseFileAttributes) |
         (bSmall ? APIsEnums.ShellGetFileInformationFlags.SmallIcon : APIsEnums.ShellGetFileInformationFlags.LargeIcon);
     SHGetFileInfo(strPath,
                   FILE_ATTRIBUTE_NORMAL,
                   out info,
                   (uint)Marshal.SizeOf(info),
                   flags);
     System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(info.hIcon);
     return(icon);
 }
Example #2
0
 public static extern int SHGetFileInfo(
     string pszPath,
     uint dwFileAttributes,
     out APIsStructs.SHFILEINFO psfi,
     uint cbfileInfo,
     APIsEnums.ShellGetFileInformationFlags uFlags);
Example #3
0
		public static System.Drawing.Icon GetFolderIcon(string strPath, bool bSmall, bool bOpen)
		{
			APIsStructs.SHFILEINFO info = new APIsStructs.SHFILEINFO(true);
			APIsEnums.ShellGetFileInformationFlags flags =
				APIsEnums.ShellGetFileInformationFlags.Icon |
				(bSmall ? APIsEnums.ShellGetFileInformationFlags.SmallIcon : APIsEnums.ShellGetFileInformationFlags.LargeIcon) |
				(bOpen ? APIsEnums.ShellGetFileInformationFlags.OpenIcon : 0) |
				(Directory.Exists(strPath) ? 0 : APIsEnums.ShellGetFileInformationFlags.UseFileAttributes);
			SHGetFileInfo(strPath,
				FILE_ATTRIBUTE_DIRECTORY,
				out info,
				(uint)Marshal.SizeOf(info),
				flags);
			System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(info.hIcon);
			return icon;
		}