Esempio n. 1
0
		public static Bitmap IconFromExtensionShell(string Extension, IconSize Size)
		{
			try
			{
				//add '.' if nessesry
				if (Extension[0] != '.') Extension = '.' + Extension;

				//temp struct for getting file shell info
				SHFILEINFO TempFileInfo = new SHFILEINFO();

				SHGetFileInfo(
					Extension,
					0,
					ref TempFileInfo,
					(uint)Marshal.SizeOf(TempFileInfo),
					SHGFI_ICON | SHGFI_USEFILEATTRIBUTES | (uint)Size);

				return GetManagedIcon(TempFileInfo.hIcon).ToBitmap();
			}
			catch (Exception e)
			{
				System.Diagnostics.Debug.WriteLine("error while" +
				  " trying to get icon for " + Extension +
				  " :" + e.Message);
				return null;
			}
		}
Esempio n. 2
0
		static extern IntPtr SHGetFileInfo(
			string pszPath,            //path
			uint dwFileAttributes,    //attributes
			ref SHFILEINFO psfi,    //struct pointer
			uint cbSizeFileInfo,    //size
			uint uFlags);    //flags