public IconLocation(string fileName, int index, GILI iconFlags, SHIL size)
 {
     FileName  = string.Intern(Path.GetFullPath(fileName));
     Index     = index;
     IconFlags = iconFlags;
     Size      = size;
 }
Example #2
0
        private ImageSource GetIcon(SHIL iconSize, GILI iconAttrs)
        {
            int iconIndex = GetIconIndex(iconAttrs);

            return(iconIndex != UnindexableIconIndex
                ? _tree.IconList.GetIconByIndex(iconSize, iconIndex)
                : _tree.IconList.ExtractIcon(ParentShellFolder, _pidl, iconSize, iconAttrs));
        }
        public int GetIconOf([In] PIDLIST pidl, [In] GILI flags)
        {
            int     iconIndex;
            HRESULT hr = Com.GetIconOf(pidl, flags, out iconIndex);

            if (hr == HRESULT.S_FALSE)
            {
                return(ShellItem.NoIconIndex);
            }
            hr.ThrowIfFailed();
            return(iconIndex);
        }
        public bool?GetIconLocation(GILI inFlags, out string iconFile, out int iconIndex, out GILR resFlags)
        {
            var     sb = new StringBuilder(Native.MAX_PATH);
            HRESULT hr = Com.GetIconLocation(inFlags, sb, sb.Capacity, out iconIndex, out resFlags);

            iconFile = sb.ToString();
            if (hr == HRESULT.S_FALSE)
            {
                return(false);
            }
            else if (hr == HRESULT.E_PENDING)
            {
                return(null);
            }
            hr.ThrowIfFailed();
            return(true);
        }
Example #5
0
        private int GetIconIndex(GILI iconAttrs)
        {
            if (_iconIndex != UndefinedIconIndex)
            {
                return(_iconIndex);
            }
            if (IsDesktop)
            {
                using (PIDLIST desktopPidl = Native.SHGetKnownFolderIDList(FOLDERID.Desktop))
                    return(_iconIndex = Native.SHGetFileInfo(desktopPidl, SHGFI.SYSICONINDEX).iIcon);
            }

            Dispatcher.InvokeAsync(
                () => {
                int iconIndex;
                using (NativeShellIcon shellIcon = ParentShellFolder.QueryInterface <IShellIcon>().ToNative())
                    iconIndex = shellIcon != null ? _tree.IconList.GetIconIndex(shellIcon, _pidl, iconAttrs) : UnindexableIconIndex;
                Set(ref _iconIndex, iconIndex, "IconSmall", "IconLarge", "IconExtraLarge", "IconJumbo");
            },
                DispatcherPriority.Background);
            return(NoIconIndex);
        }
 public ImageSource GetIcon(NativeShellIcon shellIcon, PIDLIST pidl, SHIL iconSize, GILI iconFlags)
 {
     return(GetIconByIndex(iconSize, GetIconIndex(shellIcon, pidl, iconFlags)));
 }
 public int GetIconIndex(NativeShellIcon shellIcon, PIDLIST pidl, GILI iconFlags)
 {
     return(shellIcon.GetIconOf(pidl, iconFlags));
 }
        private ImageSource ExtractIcon(NativeShellFolder shellFolder, PIDLIST pidl, int iconSize, GILI iconFlags)
        {
            using (NativeExtractIcon extractIcon = shellFolder.GetUIObjectOf <IExtractIcon>(pidl).ToNative()) {
                string iconFile;
                int    iconIndex;
                GILR   iconResultFlags;
                if (!extractIcon.GetIconLocation(iconFlags, out iconFile, out iconIndex, out iconResultFlags).GetValueOrDefault())
                {
                    return(null); // TODO return default icon, schedule async icon extraction
                }
                HICON hicon;
                // TODO check cache

                /*if (!iconResultFlags.Has(GILR.NOTFILENAME))
                 *  Native.PrivateExtractIcons(iconFile, iconIndex, iconSize, out hicon, LR.LOADFROMFILE);*/
                if (!extractIcon.Extract(iconFile, iconIndex, (ushort)iconSize, out hicon) && !iconResultFlags.Has(GILR.NOTFILENAME))
                {
                    Native.PrivateExtractIcons(iconFile, iconIndex, iconSize, out hicon, LR.LOADFROMFILE);
                }
                if (hicon == IntPtr.Zero)
                {
                    return(null);
                }

                return(Native.CreateBitmapSourceFromHIcon(hicon));
            }
        }
 public ImageSource ExtractIcon(NativeShellFolder shellFolder, PIDLIST pidl, SHIL iconSize, GILI iconFlags)
 {
     return(ExtractIcon(shellFolder, pidl, IconSizeToPixels(iconSize), iconFlags));
 }