private static extern int SHGetFileInfo( string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbfileInfo, SHGFI uFlags );
public static int GetSmallIconIndex(IntPtr ipIDList) { SHFILEINFO psfi = new SHFILEINFO(); SHGFI dwflag = SHGFI.ICON | SHGFI.PIDL | SHGFI.SMALLICON | SHGFI.SYSICONINDEX; IntPtr ipIcon = SHGetFileInfo(ipIDList, 0, ref psfi, Marshal.SizeOf(psfi), dwflag); return(psfi.iIcon); }
/// <summary> /// 获取系统图标 /// </summary> /// <param name="path">文件名</param> /// <param name="dwAttr">文件信息</param> /// <param name="dwFlag">获取信息控制字</param> /// <returns></returns> private Icon GetIcon( string path, FILE_ATTRIBUTE dwAttr, SHGFI dwFlag) { SHFILEINFO fi = new SHFILEINFO(); Icon ic = null; int iTotal = (int)SHGetFileInfo(path, dwAttr, ref fi, 0, dwFlag); ic = Icon.FromHandle(fi.hIcon); return ic; }
/// <summary> /// 获取小图标索引 /// </summary> public static int GetSmallIconIndex(string strFilename) { SHFILEINFO psfi = new SHFILEINFO(); SHGFI dwflag = SHGFI.ICON | SHGFI.SMALLICON | SHGFI.SYSICONINDEX; IntPtr ipIcon = SHGetFileInfo(strFilename, 0, out psfi, Marshal.SizeOf(psfi), dwflag); return(psfi.iIcon); }
private static extern int SHGetFileInfo ( string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbfileInfo, SHGFI uFlags );
private static extern IntPtr SHGetFileInfo ( string pszPath, //一个包含要取得信息的文件相对或绝对路径的缓冲。它可以处理长或短文件名。(也就是指定的文件路径)注[1] uint dwFileAttributes, //资料上说,这个参数仅用于uFlags中包含SHGFI_USEFILEATTRIBUTES标志的情况(一般不使用)。如此,它应该是文件属性的组合:存档,只读,目录,系统等。 out SHFILEINFO psfi, uint cbfileInfo, //简单地给出上项结构的尺寸。 SHGFI uFlags //函数的核心变量,通过所有可能的标志,你就能驾驭函数的行为和实际地得到信息。 );
private static Icon GetIcon(string path, FILE_ATTRIBUTE dwAttr, SHGFI dwFlag) { SHFILEINFO fi = new SHFILEINFO(); Icon ic = null; int iTotal = (int)SHGetFileInfo(path, dwAttr, ref fi, 0, dwFlag); ic = Icon.FromHandle(fi.hIcon); return(ic); }
static public void LV_SetSmallImageList(ListView lv, string path, SHGFI icon_size_mode) { SendMessage( lv.Handle, (uint)ILM.SETIMAGELIST, (uint)LVSIL.SMALL, GetImageListPointer(path, icon_size_mode) ); }
private static IntPtr RetrieveDirectoryIconPtr(string path) { uint attributes = Win32.SHELL32_FILE_ATTRIBUTE_DIRECTORY; SHGFI flags = SHGFI.UseFileAttributes | SHGFI.Icon; SHFILEINFO shfileinfo = new SHFILEINFO(); Win32.SHGetFileInfo(path, attributes, ref shfileinfo, (uint)Marshal.SizeOf(shfileinfo), (uint)flags); return(shfileinfo.hIcon); }
private static IntPtr RetrieveFileIconPtr(string path) { uint attributes = 0;// Win32.SHELL32_FILE_ATTRIBUTE_NORMAL; SHGFI flags = /*SHGFI.UseFileAttributes | SHGFI.Icon |*/ SHGFI.SysIconIndex; SHFILEINFO shfileinfo = new SHFILEINFO(); IntPtr list = Win32.SHGetFileInfo(path, attributes, ref shfileinfo, (uint)Marshal.SizeOf(shfileinfo), (uint)flags); return(Win32.ImageList_GetIcon(list, shfileinfo.iIcon.ToInt32(), (int)ImageListDrawItemConstants.ILD_TRANSPARENT)); //return shfileinfo.hIcon; }
/// <summary> /// Returns shell info. /// </summary> /// <param name="path">Filepath of image</param> public virtual ShellInfo GetShellInfo(string path) { ShellInfo info = new ShellInfo(); try { SHFILEINFO shinfo = new SHFILEINFO(); uint structSize = (uint)Marshal.SizeOf(shinfo); SHGFI flags = SHGFI.Icon | SHGFI.SmallIcon | SHGFI.TypeName | SHGFI.UseFileAttributes; // Get the small icon and shell file type IntPtr hImg = SHGetFileInfo(path, FileAttributes.Normal, out shinfo, structSize, flags); // Get mime type info.FileType = shinfo.szTypeName; // Get small icon if (hImg != IntPtr.Zero && shinfo.hIcon != IntPtr.Zero) { using (Icon newIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon)) { info.SmallIcon = newIcon.ToBitmap(); } DestroyIcon(shinfo.hIcon); } else { info.Error = new Exception("Error reading shell icon"); } // Get large icon hImg = SHGetFileInfo(path, FileAttributes.Normal, out shinfo, structSize, SHGFI.Icon | SHGFI.LargeIcon | SHGFI.UseFileAttributes); if (hImg != IntPtr.Zero && shinfo.hIcon != IntPtr.Zero) { using (Icon newIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon)) { info.LargeIcon = newIcon.ToBitmap(); } DestroyIcon(shinfo.hIcon); } else { info.Error = new Exception("Error reading shell icon"); } } catch (Exception e) { info.Error = e; } return(info); }
public static ImageSource GetFileIconImageSource(string path, bool large, bool file) { var shinfo = new SHFILEINFO(); SHGFI flags = SHGFI.UseFileAttributes | SHGFI.Icon | (large ? SHGFI.LargeIcon : SHGFI.SmallIcon); SHGetFileInfo(path, file ? FileAttribute.Normal : FileAttribute.Directory, ref shinfo, (uint)Marshal.SizeOf(shinfo), flags); ImageSource image = Imaging.CreateBitmapSourceFromHIcon(shinfo.hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); DestroyIcon(shinfo.hIcon); return(image); }
private static Icon GetIcon(string fileName, SHGFI flags, bool isFolder = false) { SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImgSmall = Win32.SHGetFileInfo(fileName, isFolder ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo), (uint)(SHGFI.Icon | flags)); Icon icon = (Icon)System.Drawing.Icon.FromHandle(shinfo.hIcon).Clone(); Win32.DestroyIcon(shinfo.hIcon); return(icon); }
/// <summary> /// Gets the icon defined by the set of flags provided. /// </summary> /// <param name="iconType">Flags to specify type of the icon.</param> /// <returns><see cref="Icon"/> if successful; <c>null</c> otherwise.</returns> public Icon GetIcon(ShellIconType iconType = ShellIconType.Large) { const SHGFI baseFlags = SHGFI.SHGFI_ICON | SHGFI.SHGFI_PIDL; var shfi = new SHFILEINFO(); var ret = SHGetFileInfo(PIDL, 0, ref shfi, SHFILEINFO.Size, baseFlags | SHGFI.SHGFI_USEFILEATTRIBUTES | (SHGFI)iconType); if (ret == IntPtr.Zero) { ret = SHGetFileInfo(PIDL, 0, ref shfi, SHFILEINFO.Size, baseFlags | (SHGFI)iconType); } return(ret == IntPtr.Zero ? null : GetClonedIcon(shfi.hIcon)); }
/// <summary>Gets the Shell icon for the given file name or extension.</summary> /// <param name="fileNameOrExtension">The file name or extension .</param> /// <param name="iconType">Flags to specify the type of the icon to retrieve. This uses the <see cref="SHGetFileInfo(string, System.IO.FileAttributes, ref SHFILEINFO, int, SHGFI)"/> method and can only retrieve small or large icons.</param> /// <returns>An <see cref="Icon"/> instance if found; otherwise <see langword="null"/>.</returns> public static Icon GetFileIcon(string fileNameOrExtension, ShellIconType iconType = ShellIconType.Large) { const SHGFI baseFlags = SHGFI.SHGFI_USEFILEATTRIBUTES | SHGFI.SHGFI_ICON; var shfi = new SHFILEINFO(); var ret = SHGetFileInfo(fileNameOrExtension, 0, ref shfi, shfiSz, baseFlags | (SHGFI)iconType); if (ret == IntPtr.Zero) { ret = SHGetFileInfo(fileNameOrExtension, 0, ref shfi, shfiSz, SHGFI.SHGFI_ICON | (SHGFI)iconType); } return(ret == IntPtr.Zero ? null : IconLocation.GetClonedIcon(shfi.hIcon)); }
static int GetIconIndex(string pszFile, bool isDir = false) { SHFILEINFO sfi = new SHFILEINFO(); SHGFI flag = SHGFI.SysIconIndex | SHGFI.LargeIcon; if (!isDir) { flag = flag | SHGFI.UseFileAttributes; } SHGetFileInfo(pszFile, 0, ref sfi, (uint)Marshal.SizeOf(sfi), (uint)(flag)); return(sfi.iIcon); }
static ShellImageList() { const SHGFI baseFlags = SHGFI.SHGFI_USEFILEATTRIBUTES | SHGFI.SHGFI_SYSICONINDEX; var shfiSz = Marshal.SizeOf(typeof(SHFILEINFO)); var shfiSmall = new SHFILEINFO(); smallImageListHandle = SHGetFileInfo(".txt", FileAttributes.Normal, ref shfiSmall, shfiSz, baseFlags | SHGFI.SHGFI_SMALLICON); var shfiLarge = new SHFILEINFO(); largeImageListHandle = SHGetFileInfo(".txt", FileAttributes.Normal, ref shfiLarge, shfiSz, baseFlags | SHGFI.SHGFI_LARGEICON); }
public void Add(string extension) { // Add the following extension properties into the internal // dictionary. If it is already there, we will not do anything if (_fileTypes.ContainsKey(extension)) { return; } // Not found, get the file info for this extension from the system // Get a dummy file name string dummyFileName = Path.ChangeExtension(@"C:\Dummy", extension); SHFILEINFO shinfo = new SHFILEINFO(); SHGFI flags = SHGFI.SHGFI_ICON | SHGFI.SHGFI_SMALLICON | SHGFI.SHGFI_USEFILEATTRIBUTES | SHGFI.SHGFI_TYPENAME; IntPtr ret = SHGetFileInfo( dummyFileName, string.Compare(extension, DiretoryType, StringComparison.OrdinalIgnoreCase) == 0 ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL, ref shinfo, Marshal.SizeOf(shinfo), flags); // The icon is returned in the hIcon member of the shinfo struct. MyFileType fileType = new MyFileType(); if (ret != IntPtr.Zero) { fileType.Description = shinfo.szTypeName; if (shinfo.hIcon != IntPtr.Zero) { _imageList.Images.Add(Icon.FromHandle(shinfo.hIcon)); fileType.ImageIndex = _imageList.Images.Count - 1; } else { fileType.ImageIndex = -1; } } else { fileType.Description = "Unknown"; fileType.ImageIndex = -1; } // Add it to the dictionary _fileTypes.Add(extension, fileType); }
public void Initialize(ListView listView, SHGFI iconReadStyle, SHGFI iconWriteStyle) { Debug.Print("Initialize Directories\n"); foreach ( KeyValuePair <string, CsShellFile_ListItem> mojo in CurrentShellPath.Directories.Paths) { DirectoryInfo directoryInfo = new DirectoryInfo(mojo.Value.Path); using (CsShellFile shellFile = new CsShellFile(mojo.Value.Path, iconWriteStyle)) { ListViewItem listViewItem = new ListViewItem(directoryInfo.Name); listViewItem.ImageIndex = (int)shellFile.IIcon; if (listView.Groups[shellFile.TypeName] == null) { listView.Groups.Add(shellFile.TypeName, shellFile.TypeName); } listViewItem.Group = listView.Groups[shellFile.TypeName]; listViewItem.SubItems.Add(shellFile.TypeName); listView.Items.Add(listViewItem); } } Debug.Print("Initialize Files\n"); foreach ( KeyValuePair <string, CsShellFile_ListItem> mojo in CurrentShellPath.Files.Paths) { FileInfo FI = new FileInfo(mojo.Value.Path); ListViewItem listItem = new ListViewItem(FI.Name); SHFileInfo shFile = SHFileInfo.Create(mojo.Value.Path, iconWriteStyle); listItem.ImageIndex = (int)shFile.iIcon; if (listView.Groups[shFile.szTypeName] == null) { listView.Groups.Add(shFile.szTypeName, shFile.szTypeName); } listItem.Group = listView.Groups[shFile.szTypeName]; listItem.SubItems.Add(mojo.Value.TypeName); listItem.SubItems.Add(checkType(Path.GetExtension(mojo.Value.Path).Trim('.'))); listView.Items.Add(listItem); User32.DestroyIcon(shFile.hIcon); } User32.SendMessage(listView.Handle, (uint)wm_message.LVM_SETIMAGELIST, (uint)LVSIL.NORMAL, Shell32.ImgListPtr(CurrentPath, iconReadStyle | SHGFI.SYSICONINDEX)); User32.SendMessage(listView.Handle, (uint)wm_message.LVM_SETIMAGELIST, (uint)LVSIL.SMALL, Shell32.ImgListPtr(CurrentPath, iconReadStyle | SHGFI.SYSICONINDEX)); }
public static BitmapSource GetIcon(String path, Boolean open, bool floppy) { if (floppy) { BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri("data\\floppy.png", UriKind.Relative); image.EndInit(); return(image); } /* * Passing in the file attributes to SHGetFileInfo is noticebly faster. * See http://www.codeguru.com/cpp/com-tech/shell/article.php/c4511/ */ UInt32 fileAttributes = GetFileAttributes(path); SHGFI flags = SHGFI.SHGFI_ICON | SHGFI.SHGFI_SMALLICON | SHGFI.SHGFI_USEFILEATTRIBUTES; if (open) { flags |= SHGFI.SHGFI_OPENICON; } SHFILEINFO info = new SHFILEINFO(); SHGetFileInfo(path, fileAttributes, out info, (uint)Marshal.SizeOf(info), flags); if (info.hIcon != IntPtr.Zero) { try { return(System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(info.hIcon, new Int32Rect(0, 0, 16, 16), BitmapSizeOptions.FromEmptyOptions())); } catch (ArgumentException) { // Ugly fix for dodgy HRESULT, see http://code.google.com/p/coldemoplayer/issues/detail?id=1 return(null); } finally { DestroyIcon(info.hIcon); } } return(null); }
/// <summary> /// Constructor. Create a sub-item shell item object. /// </summary> /// <param name="shDesktop">IShellFolder interface of the Desktop</param> /// <param name="pIDL">The fully qualified PIDL for this shell item</param> /// <param name="shParent">The ShellItem object for this item's parent</param> public ShellItem(IShellFolder shDesktop, IntPtr pIDL, ShellItem shParent) { // We need the Desktop shell item to exist first. if (m_bHaveRootShell == false) { throw new Exception("The root shell item must be created before creating a sub-item"); } // Create the FQ PIDL for this new item. m_pIDL = NativeShellApi.ILCombine(shParent.PIDL, pIDL); // Get the properties of this item. SFGAOF uFlags = SFGAOF.SFGAO_FOLDER | SFGAOF.SFGAO_HASSUBFOLDER; // Here we get some basic attributes. shDesktop.GetAttributesOf(1, out m_pIDL, out uFlags); IsFolder = Convert.ToBoolean(uFlags & SFGAOF.SFGAO_FOLDER); HasSubFolder = Convert.ToBoolean(uFlags & SFGAOF.SFGAO_HASSUBFOLDER); // Now we want to get extended attributes such as the icon index etc. SHFILEINFO shInfo = new SHFILEINFO(); SHGFI vFlags = SHGFI.SHGFI_SMALLICON | SHGFI.SHGFI_SYSICONINDEX | SHGFI.SHGFI_PIDL | SHGFI.SHGFI_DISPLAYNAME; NativeShellApi.SHGetFileInfo(m_pIDL, 0, out shInfo, (uint)Marshal.SizeOf(shInfo), vFlags); DisplayName = shInfo.szDisplayName; IconIndex = shInfo.iIcon; Path = GetPath(); // Create the IShellFolder interface for this item. if (IsFolder) { uint hRes = shParent.m_shShellFolder.BindToObject(pIDL, IntPtr.Zero, ref NativeShellApi.IID_IShellFolder, out m_shShellFolder); if (hRes != 0) { Marshal.ThrowExceptionForHR((int)hRes); } } }
public static Icon GetJumboFileIcon(string filePath, bool jumboSize = true) { SHFILEINFO shfi = new SHFILEINFO(); SHGFI flags = SHGFI.SysIconIndex | SHGFI.UseFileAttributes; SHGetFileInfo(filePath, 0, ref shfi, (uint)Marshal.SizeOf(shfi), (uint)flags); IImageList spiml = null; Guid guil = new Guid(NativeConstants.IID_IImageList2); SHGetImageList(jumboSize ? NativeConstants.SHIL_JUMBO : NativeConstants.SHIL_EXTRALARGE, ref guil, ref spiml); IntPtr hIcon = IntPtr.Zero; spiml.GetIcon(shfi.iIcon, NativeConstants.ILD_TRANSPARENT | NativeConstants.ILD_IMAGE, ref hIcon); Icon icon = (Icon)Icon.FromHandle(hIcon).Clone(); DestroyIcon(hIcon); return(icon); }
public static Bitmap GetIcon(string path, IconSize size, out string typeName) { // help from https://pontusmunck.com/2007/02/01/preserving-transparency-when-converting-icon-to-bitmap/ // and http://www.pinvoke.net/default.aspx/shell32.SHGetFileInfo SHFILEINFO info = new SHFILEINFO(); int cbFileInfo = Marshal.SizeOf(info); SHGFI flags = SHGFI.Icon | (SHGFI)size | SHGFI.UseFileAttributes | SHGFI.TypeName; SHGetFileInfo(path, 256, ref info, (uint)cbFileInfo, (uint)flags); typeName = info.szTypeName; using (Icon ico = Icon.FromHandle(info.hIcon)) { Bitmap bmp = new Bitmap(ico.Size.Width, ico.Size.Height); using (Graphics g = Graphics.FromImage(bmp)) { g.DrawIcon(ico, 0, 0); } return(bmp); } }
public static Icon GetFileIcon(string filePath, bool isSmallIcon) { SHFILEINFO shfi = new SHFILEINFO(); SHGFI flags = SHGFI.Icon; if (isSmallIcon) { flags |= SHGFI.SmallIcon; } else { flags |= SHGFI.LargeIcon; } SHGetFileInfo(filePath, 0, ref shfi, (uint)Marshal.SizeOf(shfi), (uint)flags); Icon icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone(); DestroyIcon(shfi.hIcon); return(icon); }
/// <summary> /// Get the associated Icon for a file or application, this method always returns /// an icon. If the strPath is invalid or there is no idonc the default icon is returned /// </summary> /// <param name="strPath">full path to the file</param> /// <param name="bSmall">if true, the 16x16 icon is returned otherwise the 32x32</param> /// <returns></returns> public static Icon GetIcon(string strPath, bool bSmall) { var info = new SHFILEINFO(); int cbFileInfo = Marshal.SizeOf(info); SHGFI flags = SHGFI.Icon | SHGFI.UseFileAttributes; if (bSmall) { flags = flags | SHGFI.SmallIcon; } else { flags = flags | SHGFI.LargeIcon; } SHGetFileInfo(strPath, 256, out info, (uint)cbFileInfo, flags); try { return(Icon.FromHandle(info.hIcon)); } catch (ArgumentException) { return(null); } }
private static void getAttributes(bool isDirectory, bool forceLoadFromDisk, IconSize _size, out FileAttribute dwAttr, out SHGFI dwFlags) { dwFlags = SHGFI.SHGFI_SYSICONINDEX; dwAttr = 0; if (_size == IconSize.small) { dwFlags |= SHGFI.SHGFI_SMALLICON; } if (isDirectory) { dwAttr = FileAttribute.FILE_ATTRIBUTE_DIRECTORY; } else if (!forceLoadFromDisk) { dwFlags |= SHGFI.SHGFI_USEFILEATTRIBUTES; dwAttr = FileAttribute.FILE_ATTRIBUTE_NORMAL; } }
/// <summary> /// Get the associated Icon for a file or application, this method always returns /// an icon. If the strPath is invalid or there is no icon, the default icon is returned. /// </summary> public static Icon GetFileIcon(String path, Boolean small, Boolean overlays) { SHFILEINFO info = new SHFILEINFO(true); Int32 cbFileInfo = Marshal.SizeOf(info); SHGFI flags = SHGFI.Icon | SHGFI.UseFileAttributes; if (small) { flags |= SHGFI.SmallIcon; } else { flags |= SHGFI.LargeIcon; } if (overlays) { flags |= SHGFI.AddOverlays; // Get overlays too... } SHGetFileInfo(path, 0x00000080, out info, (UInt32)cbFileInfo, flags); Icon icon = (Icon)Icon.FromHandle(info.hIcon).Clone(); DestroyIcon(info.hIcon); return(icon); }
private static extern IntPtr SHGetFileInfo( string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, SHGFI uFlags);
public static extern IntPtr SHGetFileInfo(IntPtr pIDL, uint dwFileAttributes, out SHFILEINFO psfi, uint cbFileInfo, SHGFI uFlags);
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttribs, out SHFILEINFO psfi, uint cbFileInfo, SHGFI uFlags);
public static extern IntPtr SHGetFileInfo(IntPtr pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, SHGFI uFlags);
private static ImageSource GetIcon(string fileName, SHGFI flags, bool isFolder = false) { SHFILEINFO shinfo = new SHFILEINFO(); Icon icon = null; ImageSource img = null; try { IntPtr hImgSmall = Win32.SHGetFileInfo(fileName, isFolder ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint) Marshal.SizeOf(shinfo), (uint) (SHGFI.SysIconIndex | flags)); IntPtr iconHandle = Win32.ImageList_GetIcon(hImgSmall, (int) shinfo.iIcon, 0); icon = (Icon) System.Drawing.Icon.FromHandle(iconHandle).Clone(); img = GetImageSource(icon); } catch (Exception) { img = GetIcon(".exe", flags | SHGFI.UseFileAttributes); } finally { Win32.DestroyIcon(shinfo.hIcon); if(icon != null) icon.Dispose(); } return img; }
public static extern IntPtr SHGetFileInfo([In, MarshalAs(UnmanagedType.LPTStr)] string pszPath, uint dwFileAttributes, [In, Out] ref SHFILEINFO psfi, int cbFileInfo, SHGFI uFlags);
public static extern IntPtr SHGetFileInfo( IntPtr pidl, uint dwFileAttributes, ref SHFILEINFO psfi, int cbSizeFileInfo, SHGFI flags );
private extern static IntPtr SHGetFileInfo ( string pszPath, //指定的文件名 FILE_ATTRIBUTE dwFileAttributes, //文件属性 ref SHFILEINFO sfi, //返回获得的文件信息,是一个记录类型 int cbFileInfo, //文件的类型名 SHGFI uFlags );
private static Icon GetIcon(string fileName, SHGFI flags, bool isFolder = false) { SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImgSmall = Win32.SHGetFileInfo(fileName, isFolder ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo), (uint)(SHGFI.Icon | flags)); Icon icon = (Icon)System.Drawing.Icon.FromHandle(shinfo.hIcon).Clone(); Win32.DestroyIcon(shinfo.hIcon); return icon; }
internal static extern Int32 SHGetFileInfo (string pszPath, uint dwFileAttributes, out ShellFileInformationStructure psfi, uint cbfileInfo, SHGFI uFlags);
private static extern IntPtr SHGetFileInfo(string pszPath, FILE_ATTRIBUTE dwFileAttributes, ref SHFILEINFO sfi, int cbFileInfo, SHGFI uFlags);
public static SHFILEINFO? GetInfo(string filename, SHGFI flags) { SHFILEINFO info = new SHFILEINFO(true); int szInfo = Marshal.SizeOf (info); int result = (int)SHGetFileInfo (filename, 0, ref info, szInfo, (int)flags); return result != 0? new Nullable<SHFILEINFO> (info): null; }
public static IntPtr SHGetFileInfo(string pszPath, FileAttributes dwFileAttributes, ref SHFILEINFO psfi, SHGFI Flags) { return SHGetFileInfo(pszPath, dwFileAttributes, ref psfi, (uint) Marshal.SizeOf(((SHFILEINFO) psfi).GetType()), (uint) Flags); }
internal static extern IntPtr SHGetFileInfo( string pszPath, FileAttributes dwFileAttributes, ref SHFILEINFO sfi, int cbFileInfo, SHGFI uFlags);
private static Icon GetIcon(string path, FILE_ATTRIBUTE dwAttr, SHGFI dwFlag) { SHFILEINFO sfi = new SHFILEINFO(); int num1 = (int)SHGetFileInfo(path, dwAttr, ref sfi, 0, dwFlag); return Icon.FromHandle(sfi.hIcon); }
public static extern IntPtr SHGetFileInfo(IntPtr ppidl, FileAttribute dwFileAttributes, ref ShFileInfo sfi, int cbFileInfo, SHGFI uFlags);
public static extern IntPtr SHGetFileInfo([MarshalAs(UnmanagedType.LPTStr)] string pszPath, uint dwFileAttribs, out SHFILEINFO psfi, uint cbFileInfo, SHGFI uFlags);
public static extern IntPtr SHGetFileInfo( IntPtr ppidl, FILE_ATTRIBUTE dwFileAttributes, ref SHFILEINFO sfi, int cbFileInfo, SHGFI uFlags);
private static extern IntPtr SHGetFileInfo(string pszPath, FileAttributes dwFileAttributes, out SHFILEINFO psfi, uint cbFileInfo, SHGFI uFlags);
public static extern IntPtr SHGetFileInfo(string pszPath, FileAttribute dwFileAttributes, ref ShFileInfo sfi, int cbFileInfo, SHGFI uFlags);
public static extern Int32 SHGetFileInfo(String pszPath, UInt32 dwFileAttributes, out SHFILEINFO psfi, UInt32 cbfileInfo, SHGFI uFlags);
public static extern IntPtr SHGetFileInfo(string path, FileAttributes fileAttributes, ref ShFileInfo psfi, int fileInfo, SHGFI flags);
public static extern IntPtr SHGetFileInfo(string pszPath, int dwFileAttributes, out SHFILEINFO psfi, uint cbFileInfo, SHGFI uFlags);
private static IntPtr GetIcon(string filename, SHGFI flags) { SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hIconInfo; if ((File.GetAttributes(filename) & FileAttributes.Directory) == FileAttributes.Directory && !filename.StartsWith("\\")) { hIconInfo = Win32.SHGetFileInfo(filename, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY, ref shinfo, (uint)Marshal.SizeOf(shinfo), (uint)(SHGFI.SysIconIndex | flags)); } else { hIconInfo = Win32.SHGetFileInfo(filename, FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo), (uint)(SHGFI.UseFileAttributes | SHGFI.SysIconIndex | flags)); } IntPtr hIcon = Win32.ImageList_GetIcon(hIconInfo, shinfo.iIcon.ToInt32(), (int)0x00000001); Win32.DestroyIcon(shinfo.hIcon); return hIcon; }
private static extern int SHGetFileInfoA( uint pidl, uint fileAttributes, out SHFILEINFO fi, uint fileInfo, SHGFI flags);