public static Icon GetFolderIcon(IconSize _size, FolderType _folderType) { // Need to add size check, although errors generated at present! uint flags = ShellApi.SHGFI_ICON | ShellApi.SHGFI_USEFILEATTRIBUTES; if (FolderType.Open == _folderType) { flags += ShellApi.SHGFI_OPENICON; } if (IconSize.Small == _size) { flags += ShellApi.SHGFI_SMALLICON; } else { flags += ShellApi.SHGFI_LARGEICON; } // Get the folder icon ShellApi.SHFILEINFO shfi = new ShellApi.SHFILEINFO(); ShellApi.SHGetFileInfo(null, ShellApi.FILE_ATTRIBUTE_DIRECTORY, out shfi, (uint)Marshal.SizeOf(shfi), flags); // Now clone the icon, so that it can be successfully stored in an ImageList Icon icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone(); Api.DestroyIcon(shfi.hIcon); // Cleanup return(icon); }
/// <summary> /// /// </summary> /// <param name="_fileName"></param> /// <param name="_size"></param> /// <param name="_linkOverlay"></param> /// <returns></returns> public static Icon GetFileIcon(string _fileName, IconSize _size, bool _linkOverlay) { ShellApi.SHFILEINFO shfi = new ShellApi.SHFILEINFO(); uint flags = ShellApi.SHGFI_ICON | ShellApi.SHGFI_USEFILEATTRIBUTES; if (_linkOverlay) { flags += ShellApi.SHGFI_LINKOVERLAY; } if (_size == IconSize.Small) { flags += ShellApi.SHGFI_SMALLICON; } else { flags += ShellApi.SHGFI_LARGEICON; } ShellApi.SHGetFileInfo(_fileName, ShellApi.FILE_ATTRIBUTE_NORMAL, out shfi, (uint)Marshal.SizeOf(shfi), flags); Icon icon = Icon.FromHandle(shfi.hIcon); return(icon); }
public static IntPtr getIcon(String absolutePath, Boolean getLargeIcon) { ShellApi.SHFILEINFO shinfo = new ShellApi.SHFILEINFO(); if (ShellApi.SHGetFileInfo(absolutePath, 0, out shinfo, (uint)Marshal.SizeOf(shinfo), ShellApi.SHGFI.SHGFI_ICON | (getLargeIcon ? ShellApi.SHGFI.SHGFI_LARGEICON : ShellApi.SHGFI.SHGFI_SMALLICON)) == IntPtr.Zero) { return(IntPtr.Zero); } return(shinfo.hIcon); }
public static int getAttribute(string path) { ShellApi.SHFILEINFO shinfo = new ShellApi.SHFILEINFO(); if (ShellApi.SHGetFileInfo(path, 0, out shinfo, (uint)Marshal.SizeOf(shinfo), ShellApi.SHGFI.SHGFI_ATTRIBUTES) == IntPtr.Zero) { return(0); } return((int)shinfo.dwAttributes); }
public static string getFolderType(string path) { ShellApi.SHFILEINFO shinfo = new ShellApi.SHFILEINFO(); if (ShellApi.SHGetFileInfo(path, 0, out shinfo, (uint)Marshal.SizeOf(shinfo), ShellApi.SHGFI.SHGFI_TYPENAME) == IntPtr.Zero) { return(null); } return(shinfo.szTypeName); }
public static String getFolderType(IntPtr pIDL) { ShellApi.SHFILEINFO fileInfo = new ShellApi.SHFILEINFO(); ShellApi.SHGetFileInfo(pIDL, 0, out fileInfo, (uint)Marshal.SizeOf(fileInfo), ShellApi.SHGFI.SHGFI_PIDL | ShellApi.SHGFI.SHGFI_TYPENAME); return(fileInfo.szTypeName); }
public static IntPtr getIcon(String absolutePath, Boolean getLargeIcon) { ShellApi.SHFILEINFO shinfo = new ShellApi.SHFILEINFO(); if (ShellApi.SHGetFileInfo(absolutePath, 0, out shinfo, (uint)Marshal.SizeOf(shinfo), ShellApi.SHGFI.SHGFI_ICON | (getLargeIcon ? ShellApi.SHGFI.SHGFI_LARGEICON : ShellApi.SHGFI.SHGFI_SMALLICON)) == IntPtr.Zero) { return IntPtr.Zero; } return shinfo.hIcon; }
public static String getFolderType(IntPtr pIDL) { ShellApi.SHFILEINFO fileInfo = new ShellApi.SHFILEINFO(); ShellApi.SHGetFileInfo(pIDL, 0, out fileInfo, (uint)Marshal.SizeOf(fileInfo), ShellApi.SHGFI.SHGFI_PIDL | ShellApi.SHGFI.SHGFI_TYPENAME); return fileInfo.szTypeName; }
public static string getFolderType(string path) { ShellApi.SHFILEINFO shinfo = new ShellApi.SHFILEINFO(); if (ShellApi.SHGetFileInfo(path, 0, out shinfo, (uint)Marshal.SizeOf(shinfo), ShellApi.SHGFI.SHGFI_TYPENAME) == IntPtr.Zero) { return null; } return shinfo.szTypeName; }
public static int getAttribute(string path) { ShellApi.SHFILEINFO shinfo = new ShellApi.SHFILEINFO(); if (ShellApi.SHGetFileInfo(path, 0, out shinfo, (uint)Marshal.SizeOf(shinfo), ShellApi.SHGFI.SHGFI_ATTRIBUTES) == IntPtr.Zero) { return 0; } return (int)shinfo.dwAttributes; }