private static Icon GetSystemIcon(string path, IconSizeEnum iconsize) { try { Win32.SHFILEINFO psfi = new Win32.SHFILEINFO(); int dwFileAttributes = 128; Win32.SHGFI uFlags = Win32.SHGFI.SHGFI_SYSICONINDEX; if (Win32.SHGetFileInfo(path, dwFileAttributes, out psfi, (uint)Marshal.SizeOf((object)psfi), uFlags) == 0) { return((Icon)null); } int i = psfi.iIcon; Guid riid = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950"); Win32.IImageList ppv; Win32.SHGetImageList((int)iconsize, ref riid, out ppv); IntPtr picon = IntPtr.Zero; int flags = 1; ppv.GetIcon(i, flags, ref picon); Icon icon = (Icon)Icon.FromHandle(picon).Clone(); Win32.DestroyIcon(psfi.hIcon); return(icon); } catch { } return((Icon)null); }
public static Icon GetFileIcon(string path, IconSizeEnum iconsize) { if (string.IsNullOrEmpty(path)) return (Icon)null; try { if (!File.Exists(path) && !Directory.Exists(path)) { if (path.Equals("\\")) goto nullIcon; } //Mono dont support PNG icon (crash if try to use ICON.ToBitmap()) if ((bool)Globals.RuntimeSettings["Mono"] == true) { return GetIcon(path); } if ((int)Globals.RuntimeSettings["defaultFileIconType"] != 16384) { return GetIcon(path); } DelegateGetSystemIcon delegateGetSystemIcon = new DelegateGetSystemIcon(GetSystemIcon); IAsyncResult result = delegateGetSystemIcon.BeginInvoke(path, iconsize, (AsyncCallback)null, (object)null); return delegateGetSystemIcon.EndInvoke(result); } catch { } nullIcon: return (Icon)null; }
public static System.Drawing.Bitmap GetBitmapFromFilePath( string filepath, IconSizeEnum iconsize) { IntPtr hIcon = GetIconHandleFromFilePath(filepath, iconsize); return(getBitmapFromIconHandle(hIcon)); }
private static Icon GetSystemIcon(string path, IconSizeEnum iconsize) { try { Win32.SHFILEINFO psfi = new Win32.SHFILEINFO(); int dwFileAttributes = 128; Win32.SHGFI uFlags = Win32.SHGFI.SHGFI_SYSICONINDEX; if (Win32.SHGetFileInfo(path, dwFileAttributes, out psfi, (uint)Marshal.SizeOf((object)psfi), uFlags) == 0) return (Icon)null; int i = psfi.iIcon; Guid riid = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950"); Win32.IImageList ppv; Win32.SHGetImageList((int)iconsize, ref riid, out ppv); IntPtr picon = IntPtr.Zero; int flags = 1; ppv.GetIcon(i, flags, ref picon); Icon icon = (Icon)Icon.FromHandle(picon).Clone(); Win32.DestroyIcon(psfi.hIcon); return icon; } catch { } return (Icon)null; }
public static Icon GetFileIcon(string path, IconSizeEnum iconsize) { if (string.IsNullOrEmpty(path)) { return((Icon)null); } try { if (!File.Exists(path) && !Directory.Exists(path)) { if (path.Equals("\\")) { goto nullIcon; } } //Mono dont support PNG icon (crash if try to use ICON.ToBitmap()) if ((bool)Globals.RuntimeSettings["Mono"] == true) { return(GetIcon(path)); } if ((int)Globals.RuntimeSettings["defaultFileIconType"] != 16384) { return(GetIcon(path)); } DelegateGetSystemIcon delegateGetSystemIcon = new DelegateGetSystemIcon(GetSystemIcon); IAsyncResult result = delegateGetSystemIcon.BeginInvoke(path, iconsize, (AsyncCallback)null, (object)null); return(delegateGetSystemIcon.EndInvoke(result)); } catch { } nullIcon: return((Icon)null); }
public static Bitmap GetBitmapFromFolderPath( string filepath, IconSizeEnum iconsize) { IntPtr hIcon = GetIconHandleFromFolderPath(filepath, iconsize); return(getBitmapFromIconHandle(hIcon)); }
private static IntPtr GetIconHandleFromFilePath(string filepath, IconSizeEnum iconsize) { var shinfo = new Shell32.SHFILEINFO(); const uint SHGFI_SYSICONINDEX = 0x4000; const int FILE_ATTRIBUTE_NORMAL = 0x80; uint flags = SHGFI_SYSICONINDEX; return(getIconHandleFromFilePathWithFlags(filepath, iconsize, ref shinfo, FILE_ATTRIBUTE_NORMAL, flags)); }
private static IntPtr getIconHandleFromFilePathWithFlags( string filepath, IconSizeEnum iconsize, ref SHFILEINFO shinfo) { const int ILD_TRANSPARENT = 1; var retval = SHGetFileInfo(filepath, 0, ref shinfo, Marshal.SizeOf(shinfo), (uint)16640); return(shinfo.hIcon); }
private static IntPtr GetIconHandleFromFolderPath(string folderpath, IconSizeEnum iconsize) { var shinfo = new Shell32.SHFILEINFO(); const uint SHGFI_ICON = 0x000000100; const uint SHGFI_USEFILEATTRIBUTES = 0x000000010; const int FILE_ATTRIBUTE_DIRECTORY = 0x00000010; uint flags = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES; return(getIconHandleFromFilePathWithFlags(folderpath, iconsize, ref shinfo, FILE_ATTRIBUTE_DIRECTORY, flags)); }
public static Icon GetIconFromPath( string filepath, IconSizeEnum iconsize) { IntPtr hIcon = IntPtr.Zero; if (Directory.Exists(filepath) || Regex.IsMatch(filepath, @"^[A-Za-z]?:[\\]?$")) { hIcon = GetIconHandleFromFolderPath(filepath, iconsize); } else if(File.Exists(filepath)) { hIcon = GetIconHandleFromFilePath(filepath, iconsize); } return GetIconFromIconHandle(hIcon); }
public static Icon GetIconFromPath( string filepath, IconSizeEnum iconsize) { IntPtr hIcon = IntPtr.Zero; if (Directory.Exists(filepath) || Regex.IsMatch(filepath, @"^[A-Za-z]?:[\\]?$")) { hIcon = GetIconHandleFromFolderPath(filepath, iconsize); } else if (File.Exists(filepath)) { hIcon = GetIconHandleFromFilePath(filepath, iconsize); } return(GetIconFromIconHandle(hIcon)); }
private static IntPtr GetIconHandleFromFilePath(string filepath, IconSizeEnum iconsize) { if (filepath.EndsWith(".exe") || filepath.EndsWith(".lnk") || filepath.EndsWith(".msi")) { var shinfo = new SHFILEINFO(); return(getIconHandleFromFilePathWithFlags(filepath, iconsize, ref shinfo)); } else { var shinfo = new SHFILEINFO(); const uint SHGFI_SYSICONINDEX = 0x4000; const int FILE_ATTRIBUTE_NORMAL = 0x80; uint flags = SHGFI_SYSICONINDEX; return(getIconHandleFromFilePathWithFlags(filepath, iconsize, ref shinfo, FILE_ATTRIBUTE_NORMAL, flags)); } }
public static Bitmap GetBitmapFromPath( string filepath, IconSizeEnum iconsize) { IntPtr hIcon = IntPtr.Zero; if (Directory.Exists(filepath)) { hIcon = GetIconHandleFromFolderPath(filepath, iconsize); } else { if (File.Exists(filepath)) { hIcon = GetIconHandleFromFilePath(filepath, iconsize); } } return getBitmapFromIconHandle(hIcon); }
public static IntPtr GetIconFromPath(string path, IconSizeEnum size) { const uint SHGFI_SYSICONINDEX = 0x4000; const int ILD_TRANSPARENT = 1; SHFILEINFO fileInfo = new(); _ = Shell32.SHGetFileInfo(path, 0, ref fileInfo, Marshal.SizeOf(fileInfo), SHGFI_SYSICONINDEX); var imageListGuid = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950"); Shell32.SHGetImageList((int)size, ref imageListGuid, out IImageList imageList); var iconIndex = fileInfo.iIcon; IntPtr iconHandle = IntPtr.Zero; imageList.GetIcon(iconIndex, ILD_TRANSPARENT, ref iconHandle); return(iconHandle); }
public static System.Drawing.Bitmap GetBitmapFromPath( string filepath, IconSizeEnum iconsize) { IntPtr hIcon = IntPtr.Zero; if (Directory.Exists(filepath)) { hIcon = GetIconHandleFromFolderPath(filepath, iconsize); } else { if (File.Exists(filepath)) { hIcon = GetIconHandleFromFilePath(filepath, iconsize); } } return(getBitmapFromIconHandle(hIcon)); }
private static IntPtr getIconHandleFromFilePathWithFlags( string filepath, IconSizeEnum iconsize, ref Shell.SHFILEINFO shinfo, int fileAttributeFlag, uint flags) { const int ILD_TRANSPARENT = 1; var retval = SHGetFileInfo(filepath, fileAttributeFlag, ref shinfo, Marshal.SizeOf(shinfo), flags); if (retval == 0) { throw (new System.IO.FileNotFoundException()); } var iconIndex = shinfo.iIcon; var iImageListGuid = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950"); var hres = SHGetImageList((int)iconsize, ref iImageListGuid, out Shell.IImageList iml); var hIcon = IntPtr.Zero; hres = iml.GetIcon(iconIndex, ILD_TRANSPARENT, ref hIcon); return(hIcon); }
private static Bitmap GetSystemBitmap(string path, IconSizeEnum iconsize) { Icon icon = GetSystemIcon(path, iconsize); return(icon.ToBitmap()); }
public static Bitmap GetBitmapFromFolderPath( string filepath, IconSizeEnum iconsize) { IntPtr hIcon = GetIconHandleFromFolderPath(filepath, iconsize); return getBitmapFromIconHandle(hIcon); }
private static IntPtr GetIconHandleFromFolderPath(string folderpath, IconSizeEnum iconsize) { var shinfo = new SHFILEINFO(); const uint SHGFI_ICON = 0x000000100; const uint SHGFI_USEFILEATTRIBUTES = 0x000000010; const int FILE_ATTRIBUTE_DIRECTORY = 0x00000010; uint flags = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES; return getIconHandleFromFilePathWithFlags(folderpath, iconsize, ref shinfo, FILE_ATTRIBUTE_DIRECTORY, flags); }
private static IntPtr getIconHandleFromFilePathWithFlags( string filepath, IconSizeEnum iconsize, ref SHFILEINFO shinfo, int fileAttributeFlag, uint flags) { const int ILD_TRANSPARENT = 1; var retval = SHGetFileInfo(filepath, fileAttributeFlag, ref shinfo, Marshal.SizeOf(shinfo), flags); if (retval == 0) throw (new FileNotFoundException()); var iconIndex = shinfo.iIcon; var iImageListGuid = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950"); IImageList iml; var hres = SHGetImageList((int)iconsize, ref iImageListGuid, out iml); var hIcon = IntPtr.Zero; hres = iml.GetIcon(iconIndex, ILD_TRANSPARENT, ref hIcon); return hIcon; }
private static IntPtr GetIconHandleFromFilePath(string filepath, IconSizeEnum iconsize) { var shinfo = new SHFILEINFO(); const uint SHGFI_SYSICONINDEX = 0x4000; const int FILE_ATTRIBUTE_NORMAL = 0x80; uint flags = SHGFI_SYSICONINDEX; return getIconHandleFromFilePathWithFlags(filepath, iconsize, ref shinfo, FILE_ATTRIBUTE_NORMAL, flags); }
private static Bitmap GetSystemBitmap(string path, IconSizeEnum iconsize) { Icon icon = GetSystemIcon(path, iconsize); return icon.ToBitmap(); }