コード例 #1
0
        /// <summary>
        /// load computer display name and icon
        /// </summary>
        /// <param name="displayName"></param>
        /// <param name="computerIcon"></param>
        public static void LoadComputer(out string displayName, out ImageSource computerIcon)
        {
            try
            {
                IntPtr ptrIDL = IntPtr.Zero;
                var    result = ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, ShellAPI.CSIDL.CSIDL_DRIVES, ref ptrIDL);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

                ShellAPI.SHFILEINFO shellInfo = new ShellAPI.SHFILEINFO();
                ShellAPI.SHGFI      vFlags    =
                    ShellAPI.SHGFI.SHGFI_SMALLICON |
                    ShellAPI.SHGFI.SHGFI_ICON |
                    ShellAPI.SHGFI.SHGFI_PIDL |
                    ShellAPI.SHGFI.SHGFI_DISPLAYNAME |
                    ShellAPI.SHGFI.SHGFI_TYPENAME |
                    ShellAPI.SHGFI.SHGFI_ADDOVERLAYS;
                ShellAPI.SHGetFileInfo(ptrIDL, 0, ref shellInfo, (uint)Marshal.SizeOf(shellInfo), vFlags);
                displayName  = shellInfo.szDisplayName;
                computerIcon = GetImageSourceFromIcon(shellInfo.hIcon);
                if (shellInfo.hIcon != IntPtr.Zero)
                {
                    User32API.DestroyIcon(shellInfo.hIcon);
                    shellInfo.hIcon = IntPtr.Zero;
                }
            }
            catch (Exception ex)
            {
                displayName  = string.Empty;
                computerIcon = null;
                LogHelper.Debug("Application Exception:", ex);
            }
        }
コード例 #2
0
        public static ImageSource LoadDriveIcon(string path)
        {
            if (path == null)
            {
                return(null);
            }
            //TT91027 - The folder's icon doesn't display in the content list while restore the backup job which target is FTP.
            //change ftp path '/' to '\' for XP.
            path = path.Replace('/', '\\');
            ShellAPI.SHFILEINFO shellInfo = new ShellAPI.SHFILEINFO();
            ShellAPI.SHGFI      vFlags    =
                ShellAPI.SHGFI.SHGFI_LARGEICON |
                ShellAPI.SHGFI.SHGFI_ICON |
                ShellAPI.SHGFI.SHGFI_USEFILEATTRIBUTES |
                ShellAPI.SHGFI.SHGFI_DISPLAYNAME;

            ShellAPI.SHGetFileInfo(path, (uint)FileAttributes.Directory, ref shellInfo, (uint)Marshal.SizeOf(shellInfo), vFlags);
            var ico = GetImageSourceFromIcon(shellInfo.hIcon);

            if (shellInfo.hIcon != IntPtr.Zero)
            {
                User32API.DestroyIcon(shellInfo.hIcon);
                shellInfo.hIcon = IntPtr.Zero;
            }
            return(ico);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="attr"></param>
        /// <returns>image,displayname,typename</returns>
        public static Tuple <ImageSource, string, string> LoadFileInfoByPath(string path, FileAttributes attr = 0)
        {
            ImageSource icon = null;

            //TT91027 - The folder's icon doesn't display in the content list while restore the backup job which target is FTP.
            //change ftp path '/' to '\' for XP.
            path = path.Replace('/', '\\');
            ShellAPI.SHFILEINFO shellInfo = new ShellAPI.SHFILEINFO();
            ShellAPI.SHGFI      vFlags    =
                ShellAPI.SHGFI.SHGFI_SMALLICON |
                ShellAPI.SHGFI.SHGFI_ICON |
                ShellAPI.SHGFI.SHGFI_USEFILEATTRIBUTES |
                ShellAPI.SHGFI.SHGFI_DISPLAYNAME |
                ShellAPI.SHGFI.SHGFI_TYPENAME;
            ShellAPI.SHGetFileInfo(path, (uint)attr, ref shellInfo, (uint)Marshal.SizeOf(shellInfo), vFlags);
            string displayName = shellInfo.szDisplayName;

            if (shellInfo.hIcon != IntPtr.Zero)
            {
                icon = GetImageSourceFromIcon(shellInfo.hIcon);
                User32API.DestroyIcon(shellInfo.hIcon);
                shellInfo.hIcon = IntPtr.Zero;
            }
            string typeName = shellInfo.szTypeName;

            return(new Tuple <ImageSource, string, string>(icon, displayName, typeName));
        }
コード例 #4
0
        public void BuildDriveList()
        {
            base.Items.Clear();

            ShellAPI.SHFILEINFO shInfo    = new ShellAPI.SHFILEINFO();
            ShellAPI.SHGFI      dwAttribs =
                ShellAPI.SHGFI.SHGFI_ICON |
                ShellAPI.SHGFI.SHGFI_SMALLICON |
                ShellAPI.SHGFI.SHGFI_SYSICONINDEX |
                ShellAPI.SHGFI.SHGFI_DISPLAYNAME;

            ListDictionary _iconDict = new ListDictionary();

            foreach (string drive in System.IO.Directory.GetLogicalDrives())
            {
                IntPtr m_pHandle = ShellAPI.SHGetFileInfo(drive, ShellAPI.FILE_ATTRIBUTE_NORMAL, ref shInfo, (uint)System.Runtime.InteropServices.Marshal.SizeOf(shInfo), dwAttribs);

                if (m_pHandle.Equals(IntPtr.Zero) == false)
                {
                    int idxIcon = 0;
                    if (_iconDict.Contains(shInfo.iIcon) == false)
                    {
                        base.ImageList.Images.Add(System.Drawing.Icon.FromHandle(shInfo.hIcon).Clone() as System.Drawing.Icon);

                        User32API.DestroyIcon(shInfo.hIcon);

                        _iconDict.Add(shInfo.iIcon, _iconDict.Count);
                        idxIcon = _iconDict.Count - 1;
                    }
                    else
                    {
                        idxIcon = Convert.ToInt32(_iconDict[shInfo.iIcon]);
                    }

                    try
                    {
                        DriveInfo drv_info = new DriveInfo(shInfo.szDisplayName.Substring(shInfo.szDisplayName.IndexOf("(") + 1, 1));
                        if (drv_info.DriveType == DriveType.CDRom)
                        {
                            ImageComboItem item = new ImageComboItem(shInfo.szDisplayName, idxIcon, false);
                            item.ItemValue = drive;
                            base.Items.Add(item);
                        }
                    }
                    catch
                    {
                    }
                }
            }

            if (base.Items.Count != 0)
            {
                base.SelectedIndex = 0;
            }
        }
コード例 #5
0
        /// <summary>
        /// Load file  icon, file type from shell
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="attributes">The attr.</param>
        public static System.Windows.Media.ImageSource LoadFileInfo(string path, out string typeName)
        {
            FileAttributes attributes;

            if (CommonProvider.Directory.Exists(path))
            {
                attributes = FileAttributes.Directory;
            }
            else if (CommonProvider.File.Exists(path))
            {
                attributes = FileAttributes.Normal;
            }
            else
            {
                typeName = string.Empty;
                return(null);
            }

            typeName = string.Empty;
            if (path == null)
            {
                return(null);
            }
            //TT91027 - The folder's icon doesn't display in the content list while restore the backup job which target is FTP.
            //change ftp path '/' to '\' for XP.
            path = path.Replace('/', '\\');
            ShellAPI.SHFILEINFO shellInfo = new ShellAPI.SHFILEINFO();
            ShellAPI.SHGFI      vFlags    =
                ShellAPI.SHGFI.SHGFI_SMALLICON |
                ShellAPI.SHGFI.SHGFI_ICON |
                ShellAPI.SHGFI.SHGFI_USEFILEATTRIBUTES |
                ShellAPI.SHGFI.SHGFI_TYPENAME;

            ShellAPI.SHGetFileInfo(path, (uint)attributes, ref shellInfo, (uint)Marshal.SizeOf(shellInfo), vFlags);
            var ico = GetImageSourceFromIcon(shellInfo.hIcon);

            //displayName = shellInfo.szDisplayName;
            if (shellInfo.hIcon != IntPtr.Zero)
            {
                User32API.DestroyIcon(shellInfo.hIcon);
                shellInfo.hIcon = IntPtr.Zero;
            }
            typeName = shellInfo.szTypeName;
            if (ico == null && attributes == FileAttributes.Directory)
            {
                ico = DefaultFolderImage;
            }
            return(ico);
        }
コード例 #6
0
 /// <summary>
 /// Load file information, dislpay name, icon, file type from shell
 /// </summary>
 /// <param name="pidl">The pidl.</param>
 void LoadFileInfo(IntPtr pidl)
 {
     ShellAPI.SHFILEINFO shellInfo = new ShellAPI.SHFILEINFO();
     ShellAPI.SHGFI      vFlags    =
         ShellAPI.SHGFI.SHGFI_SMALLICON |
         ShellAPI.SHGFI.SHGFI_ICON |
         ShellAPI.SHGFI.SHGFI_PIDL |
         ShellAPI.SHGFI.SHGFI_DISPLAYNAME |
         ShellAPI.SHGFI.SHGFI_TYPENAME |
         ShellAPI.SHGFI.SHGFI_ADDOVERLAYS;
     ShellAPI.SHGetFileInfo(pidl, 0, ref shellInfo, (uint)Marshal.SizeOf(shellInfo), vFlags);
     DisplayName = shellInfo.szDisplayName;
     if (shellInfo.hIcon != IntPtr.Zero)
     {
         Icon = GetImageSourceFromIcon(shellInfo.hIcon);
         User32API.DestroyIcon(shellInfo.hIcon);
         shellInfo.hIcon = IntPtr.Zero;
     }
     TypeName = shellInfo.szTypeName;
 }
コード例 #7
0
        /// <summary>
        /// Load file icon
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="attributes">The attr.</param>
        public static ImageSource LoadFileInfo(string path, FileAttributes attributes)
        {
            if (path == null)
            {
                return(null);
            }
            if (attributes == FileAttributes.Normal)
            {
                if (!CommonProvider.File.Exists(path))
                {
                    path = Path.GetFileName(path);
                }
            }

            //TT91027 - The folder's icon doesn't display in the content list while restore the backup job which target is FTP.
            //change ftp path '/' to '\' for XP.
            path = path.Replace('/', '\\');
            ShellAPI.SHFILEINFO shellInfo = new ShellAPI.SHFILEINFO();
            ShellAPI.SHGFI      vFlags    =
                ShellAPI.SHGFI.SHGFI_SMALLICON |
                ShellAPI.SHGFI.SHGFI_ICON |
                ShellAPI.SHGFI.SHGFI_USEFILEATTRIBUTES;

            ShellAPI.SHGetFileInfo(path, (uint)attributes, ref shellInfo, (uint)Marshal.SizeOf(shellInfo), vFlags);
            var ico = GetImageSourceFromIcon(shellInfo.hIcon);

            if (shellInfo.hIcon != IntPtr.Zero)
            {
                User32API.DestroyIcon(shellInfo.hIcon);
                shellInfo.hIcon = IntPtr.Zero;
            }

            if (ico == null && attributes == FileAttributes.Directory)
            {
                ico = DefaultFolderImage;
            }
            return(ico);
        }