Esempio n. 1
0
 public static extern IntPtr SHGetFileInfo([MarshalAs(UnmanagedType.LPTStr)] string pszPath, FileAttributes dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, ShellFileFlags uFlags);
Esempio n. 2
0
 /// <summary>
 /// Retrieves information about an object in the file system, such as a file, folder, directory, or drive root.
 /// </summary>
 /// <param name="pszPath">The path and file name. Both absolute and relative paths are valid.</param>
 /// <param name="fileAttributes">A combination of one or more file attribute flags.</param>
 /// <param name="psfi">A SHFILEINFO structure to receive the file information.</param>
 /// <param name="cbFileInfo">The size, in bytes, of the SHFILEINFO structure pointed to by the psfi parameter.</param>
 /// <param name="flags">The flags that specify the file information to retrieve.</param>
 /// <returns></returns>
 public static IntPtr SHGetFileInfo(string pszPath, FileAttributes fileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, ShellFileFlags flags)
 {
     return NativeMethods.SHGetFileInfo(pszPath, fileAttributes, ref psfi, cbFileInfo, flags);
 }
Esempio n. 3
0
        private static SHFILEINFO GetFolderIconSHInfo(IconSize size, FolderType folderType)
        {
            // Need to add size check, although errors generated at present!
            var flags = ShellFileFlags.SHGFI_ICON | ShellFileFlags.SHGFI_USEFILEATTRIBUTES;

            if (FolderType.Open == folderType)
            {
                flags |= ShellFileFlags.SHGFI_OPENICON;
            }

            if (IconSize.Small == size)
            {
                flags |= ShellFileFlags.SHGFI_SMALLICON;
            }
            else
            {
                flags |= ShellFileFlags.SHGFI_LARGEICON;
            }

            // Get the folder icon
            var info = new SHFILEINFO();
            Shell32.SHGetFileInfo(Environment.GetFolderPath(Environment.SpecialFolder.System), FileManagement.FileAttributes.FILE_ATTRIBUTE_DIRECTORY, ref info, (uint)Marshal.SizeOf(info), flags);
            return info;
        }
Esempio n. 4
0
 private static Icon GetIcon(ref SHFILEINFO info)
 {
     Icon clone = null;
     if (info.hIcon != IntPtr.Zero)
     {
         try
         {
             using (var icon = Icon.FromHandle(info.hIcon))
             {
                 clone = (Icon)icon.Clone();
             }
         }
         finally
         {
             User32.DestroyIcon(info.hIcon);
         }
     }
     return clone;
 }
Esempio n. 5
0
        private static SHFILEINFO GetFileIconSHInfo(string name, IconSize size, bool linkOverlay)
        {
            var flags = ShellFileFlags.SHGFI_ICON | ShellFileFlags.SHGFI_USEFILEATTRIBUTES;

            if (linkOverlay) { flags |= ShellFileFlags.SHGFI_LINKOVERLAY; }

            /* Check the size specified for return. */
            if (size == IconSize.Small)
            {
                flags |= ShellFileFlags.SHGFI_SMALLICON;
            }
            else
            {
                flags |= ShellFileFlags.SHGFI_LARGEICON;
            }

            var info = new SHFILEINFO();
            Shell32.SHGetFileInfo(name, FileManagement.FileAttributes.FILE_ATTRIBUTE_NORMAL, ref info, (uint)Marshal.SizeOf(info), flags);
            return info;
        }