Beispiel #1
0
        ///
        /// lookup and return an icon from windows shell
        ///
        /// "name">path to the file
        /// "size">large or small
        /// "linkOverlay">true to include the overlay link iconlet
        /// requested icon
        public static System.Drawing.Icon GetFileIconByExt(
            string fileExt,
            EnumIconSize size,
            bool addLinkOverlay)
        {
            string tempFile = Path.GetTempPath() + Guid.NewGuid().ToString("N") + fileExt;

            try
            {
                File.WriteAllBytes(tempFile, new byte[1] {
                    0
                });

                return(GetFileIcon(tempFile, size, addLinkOverlay));
            }
            finally
            {
                try
                {
                    File.Delete(tempFile);
                }
                catch (Exception)
                {
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// lookup and return an icon from windows shell
        /// </summary>
        /// <param name="name">path to the file</param>
        /// <param name="size">large or small</param>
        /// <param name="linkOverlay">true to include the overlay link iconlet</param>
        /// <returns>requested icon</returns>
        public static System.Drawing.Icon GetFileIcon(
            string filePath,
            EnumIconSize size,
            bool addLinkOverlay)
        {
            EnumFileInfoFlags flags =
                EnumFileInfoFlags.ICON | EnumFileInfoFlags.USEFILEATTRIBUTES;

            // add link overlay if requested
            if (addLinkOverlay)
            {
                flags |= EnumFileInfoFlags.LINKOVERLAY;
            }

            // set size
            if (size == EnumIconSize.Small)
            {
                flags |= EnumFileInfoFlags.SMALLICON;
            }
            else
            {
                flags |= EnumFileInfoFlags.LARGEICON;
            }

            ShellFileInfo shellFileInfo = new ShellFileInfo();

            SHGetFileInfo(
                filePath,
                conFILE_ATTRIBUTE_NORMAL,
                ref shellFileInfo,
                (uint)System.Runtime.InteropServices.Marshal.SizeOf(shellFileInfo),
                (uint)flags);

            // deep copy
            System.Drawing.Icon icon =
                (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shellFileInfo.hIcon).Clone();

            // release handle
            DestroyIcon(shellFileInfo.hIcon);

            return(icon);
        }
Beispiel #3
0
        /// <summary>
        /// lookup and return an icon from windows shell
        /// </summary>
        /// <param name="folderPath">path to folder<param>
        /// <param name="size">large or small</param>
        /// <param name="folderType">open or closed</param>
        /// <returns>requested icon</returns>
        public static System.Drawing.Icon GetFolderIcon(
            string folderPath,
            EnumIconSize size,
            EnumFolderType folderType)
        {
            EnumFileInfoFlags flags =
                EnumFileInfoFlags.ICON | EnumFileInfoFlags.USEFILEATTRIBUTES;

            if (folderType == EnumFolderType.Open)
            {
                flags |= EnumFileInfoFlags.OPENICON;
            }

            if (EnumIconSize.Small == size)
            {
                flags |= EnumFileInfoFlags.SMALLICON;
            }
            else
            {
                flags |= EnumFileInfoFlags.LARGEICON;
            }

            ShellFileInfo shellFileInfo = new ShellFileInfo();

            SHGetFileInfo(
                folderPath,
                conFILE_ATTRIBUTE_DIRECTORY,
                ref shellFileInfo,
                (uint)System.Runtime.InteropServices.Marshal.SizeOf(shellFileInfo),
                (uint)flags);

            // deep copy
            System.Drawing.Icon icon =
                (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shellFileInfo.hIcon).Clone();

            // release handle
            DestroyIcon(shellFileInfo.hIcon);

            return(icon);
        }
Beispiel #4
0
 ///
 ///  lookup and return an icon from windows shell
 ///
 /// "size">large or small
 /// "folderType">open or closed
 /// requested icon
 public static System.Drawing.Icon GetFolderIcon(
     EnumIconSize size,
     EnumFolderType folderType)
 {
     return(GetFolderIcon(null, size, folderType));
 }
Beispiel #5
0
        ///
        /// lookup and return an icon from windows shell
        ///
        /// "folderPath">path to folder    
        /// "size">large or small
        /// "folderType">open or closed
        /// requested icon
        public static System.Drawing.Icon GetFolderIcon(
          string folderPath,
          EnumIconSize size,
          EnumFolderType folderType)
        {

            EnumFileInfoFlags flags =
              EnumFileInfoFlags.ICON | EnumFileInfoFlags.USEFILEATTRIBUTES;

            if (folderType == EnumFolderType.Open)
            {
                flags |= EnumFileInfoFlags.OPENICON;
            }

            if (EnumIconSize.Small == size)
            {
                flags |= EnumFileInfoFlags.SMALLICON;
            }
            else
            {
                flags |= EnumFileInfoFlags.LARGEICON;
            }

            ShellFileInfo shellFileInfo = new ShellFileInfo();
            SHGetFileInfo(
              folderPath,
              conFILE_ATTRIBUTE_DIRECTORY,
              ref shellFileInfo,
              (uint)System.Runtime.InteropServices.Marshal.SizeOf(shellFileInfo),
              (uint)flags);

            // deep copy
            System.Drawing.Icon icon =
              (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shellFileInfo.hIcon).Clone();
            // release handle
            DestroyIcon(shellFileInfo.hIcon);
            return icon;
        }
Beispiel #6
0
 ///
 ///  lookup and return an icon from windows shell
 ///
 /// "size">large or small
 /// "folderType">open or closed
 /// requested icon
 public static System.Drawing.Icon GetFolderIcon(
   EnumIconSize size,
   EnumFolderType folderType)
 {
     return GetFolderIcon(null, size, folderType);
 }
Beispiel #7
0
        ///
        /// lookup and return an icon from windows shell
        ///
        /// "name">path to the file
        /// "size">large or small
        /// "linkOverlay">true to include the overlay link iconlet
        /// requested icon
        public static System.Drawing.Icon GetFileIconByExt(
          string fileExt,
          EnumIconSize size,
          bool addLinkOverlay)
        {
            string tempFile = Path.GetTempPath() + Guid.NewGuid().ToString("N") + fileExt;

            try
            {
                File.WriteAllBytes(tempFile, new byte[1] { 0 });

                return GetFileIcon(tempFile, size, addLinkOverlay);
            }
            finally
            {
                try
                {
                    File.Delete(tempFile);
                }
                catch (Exception)
                {
                }
            }            
        }
Beispiel #8
0
        public static System.Drawing.Icon GetFileIcon(string filePath,
            EnumIconSize size, bool addLinkOverlay)
        {
            EnumFileInfoFlags flags =
              EnumFileInfoFlags.ICON | EnumFileInfoFlags.USEFILEATTRIBUTES;

            // add link overlay if requested
            if (addLinkOverlay)
            {
                flags |= EnumFileInfoFlags.LINKOVERLAY;
            }

            // set size
            if (size == EnumIconSize.Small)
            {
                flags |= EnumFileInfoFlags.SMALLICON;
            }
            else
            {
                flags |= EnumFileInfoFlags.LARGEICON;
            }

            ShellFileInfo shellFileInfo = new ShellFileInfo();

            SHGetFileInfo(
              filePath,
              conFILE_ATTRIBUTE_NORMAL,
              ref shellFileInfo,
              (uint)System.Runtime.InteropServices.Marshal.SizeOf(shellFileInfo),
              (uint)flags);

            // deep copy
            System.Drawing.Icon icon =
            (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shellFileInfo.hIcon).Clone();
            
            // release handle
            DestroyIcon(shellFileInfo.hIcon);

            return icon;
        }
 public static Icon GetFolderIcon(
     EnumIconSize size,
     EnumFolderType folderType)
 {
     return GetFolderIcon(null, size, folderType);
 }
Beispiel #10
0
 public static Icon GetFolderIcon(
     EnumIconSize size,
     EnumFolderType folderType)
 {
     return(GetFolderIcon(null, size, folderType));
 }