Esempio n. 1
0
        private ImageSource GetDisplayIcon(IconSize size)
        {
            ImageSource            icon         = null;
            IShellItemImageFactory imageFactory = GetImageFactory(AbsolutePidl);

            if (imageFactory == null)
            {
                icon = IconImageConverter.GetDefaultIcon();
            }
            else
            {
                try
                {
                    int  iconPoints = IconHelper.GetSize(size);
                    SIZE imageSize  = new SIZE {
                        cx = (int)(iconPoints * DpiHelper.DpiScale), cy = (int)(iconPoints * DpiHelper.DpiScale)
                    };

                    IntPtr hBitmap = IntPtr.Zero;
                    SIIGBF flags   = 0;

                    if (size == IconSize.Small)
                    {
                        // for 16pt icons, thumbnails are too small
                        flags = SIIGBF.ICONONLY;
                    }

                    if (imageFactory?.GetImage(imageSize, flags, out hBitmap) == NativeMethods.S_OK)
                    {
                        if (hBitmap != IntPtr.Zero)
                        {
                            icon = IconImageConverter.GetImageFromHBitmap(hBitmap);
                        }
                    }
                }
                catch (Exception e)
                {
                    ShellLogger.Error($"ShellItem: Unable to get icon from ShellItemImageFactory: {e.Message}");
                }
                finally
                {
                    Marshal.FinalReleaseComObject(imageFactory);
                }
            }

            if (icon == null)
            {
                // Fall back to SHGetFileInfo
                icon = IconImageConverter.GetImageFromAssociatedIcon(AbsolutePidl, size);
            }

            if (icon == null)
            {
                icon = IconImageConverter.GetDefaultIcon();
            }

            return(icon);
        }
Esempio n. 2
0
        private void setDisplayValuesApp()
        {
            if (Windows.Count > 0 && Windows[0] is ApplicationWindow window)
            {
                if (window.IsUWP)
                {
                    _storeApp = StoreAppHelper.AppList.GetAppByAumid(window.AppUserModelID);
                    Title     = _storeApp.DisplayName;
                    Icon      = window.Icon;
                }
                else
                {
                    Title = window.WinFileDescription;

                    Task.Factory.StartNew(() =>
                    {
                        Icon = IconImageConverter.GetImageFromAssociatedIcon(window.WinFileName, IconHelper.ParseSize(Settings.Instance.TaskbarIconSize) == IconSize.Small ? IconSize.Small : IconSize.Large);
                    }, CancellationToken.None, TaskCreationOptions.None, IconHelper.IconScheduler);
                }
            }
        }