private static BitmapSource GetIconForFolder() { Win32.SHFILEINFO fileInfo = new Win32.SHFILEINFO(); IntPtr hresult = NativeMethods.SHGetFileInfo( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), (uint)FileAttributes.Directory, ref fileInfo, (uint)Marshal.SizeOf(typeof(Win32.SHFILEINFO)), Win32.SHGFI_ICON | Win32.SHGFI_ADDOVERLAYS | Win32.SHGFI_SMALLICON | Win32.SHGFI_USEFILEATTRIBUTES); if (hresult == IntPtr.Zero) { throw new ArgumentException("Couldn't get icon for folders"); } BitmapSource bitmap = Imaging.CreateBitmapSourceFromHIcon( fileInfo.hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); NativeMethods.DestroyIcon(fileInfo.hIcon); return bitmap; }
private static BitmapSource GetIconForFolder() { Win32.SHFILEINFO fileInfo = new Win32.SHFILEINFO(); IntPtr hresult = NativeMethods.SHGetFileInfo( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), (uint)FileAttributes.Directory, ref fileInfo, (uint)Marshal.SizeOf(typeof(Win32.SHFILEINFO)), Win32.SHGFI_ICON | Win32.SHGFI_ADDOVERLAYS | Win32.SHGFI_SMALLICON | Win32.SHGFI_USEFILEATTRIBUTES); if (hresult == IntPtr.Zero) { throw new ArgumentException("Couldn't get icon for folders"); } BitmapSource bitmap = Imaging.CreateBitmapSourceFromHIcon( fileInfo.hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); NativeMethods.DestroyIcon(fileInfo.hIcon); return(bitmap); }
public static extern IntPtr SHGetFileInfo( string pszPath, uint dwFileAttributes, ref Win32.SHFILEINFO psfi, uint cbFileInfo, uint uFlags);