internal static extern bool SendMessage(IntPtr hWnd, ListViewMessage message, [In, Out] ref LVITEMINDEX wParam, [In] int lParam);
public void DrawIcon(IntPtr hdc, Int32 index, IListItemEx sho, User32.RECT iconBounds, Boolean isGhosted, Boolean isHot) { if (sho.OverlayIconIndex == -1) { this._OverlayQueue.Enqueue(index); } var isPerInstance = (sho.IconType & IExtractIconPWFlags.GIL_PERINSTANCE) == IExtractIconPWFlags.GIL_PERINSTANCE; if (this._CurrentSize != 16) { Int32 width = 0; Int32 height = 0; var addornerType = this.GetAddornerType(sho); IntPtr hThumbnail = IntPtr.Zero; if ((!sho.IsThumbnailLoaded && sho.IsIconLoaded) || (sho.IsThumbnailLoaded && !sho.IsIconLoaded) || (sho.IsThumbnailLoaded && sho.IsIconLoaded) || (!sho.IsThumbnailLoaded && !sho.IsIconLoaded)) { hThumbnail = sho.GetHBitmap(addornerType == 2 ? this._CurrentSize - 7 : this._CurrentSize, true); if (hThumbnail != IntPtr.Zero) { Gdi32.ConvertPixelByPixel(hThumbnail, out width, out height); if (addornerType > 0) { this.DrawWithAddorner(hdc, iconBounds, isGhosted, width, height, hThumbnail, addornerType); } else { Gdi32.NativeDraw(hdc, hThumbnail, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2, width, height, isGhosted); } if (addornerType == 2) { width = width + 7; height = height + 7; } sho.IsNeedRefreshing = ((width > height && width != this._CurrentSize) || (width < height && height != this._CurrentSize) || (width == height && width != this._CurrentSize)) && !sho.IsOnlyLowQuality; if (!sho.IsNeedRefreshing) { sho.IsThumbnailLoaded = true; sho.IsIconLoaded = true; } } } if (hThumbnail == IntPtr.Zero && !sho.IsThumbnailLoaded && !sho.IsIconLoaded || sho.IsNeedRefreshing) { Task.Run(() => { this._ThumbnailsForCacheLoad.Enqueue(index); }); } if (hThumbnail == IntPtr.Zero && !sho.IsIconLoaded && isPerInstance) { Task.Run(() => { this._IconsForRetreval.Enqueue(index); }); this.DrawDefaultIcons(hdc, sho, iconBounds); } if (hThumbnail == IntPtr.Zero && (sho.IsIconLoaded || !isPerInstance)) { if (!sho.IsRCWSet && isPerInstance) { Task.Run(() => { this._IconsForRetreval.Enqueue(index); }); this.DrawDefaultIcons(hdc, sho, iconBounds); } else { hThumbnail = sho.GetHBitmap(this._CurrentSize, false); Gdi32.ConvertPixelByPixel(hThumbnail, out width, out height); Gdi32.NativeDraw(hdc, hThumbnail, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2, width, height, isGhosted); } } Gdi32.DeleteObject(hThumbnail); using (var g = Graphics.FromHdc(hdc)) { if (this._ShellViewEx.ShowCheckboxes && this._ShellViewEx.View != ShellViewStyle.Details && this._ShellViewEx.View != ShellViewStyle.List) { /* * var lvi = new LVITEMINDEX(); * lvi.iItem = index; * lvi.iGroup = this._ShellViewEx.GetGroupIndex(index); */ var iGroup = this._ShellViewEx.GetGroupIndex(index); var lvItem = new LVITEM() { iItem = index, iGroupId = iGroup, iGroup = iGroup, mask = LVIF.LVIF_STATE, stateMask = LVIS.LVIS_SELECTED }; var lvItemImageMask = new LVITEM() { iItem = index, iGroupId = iGroup, iGroup = iGroup, mask = LVIF.LVIF_STATE, stateMask = LVIS.LVIS_STATEIMAGEMASK }; var res = User32.SendMessage(this._ShellViewEx.LVHandle, MSG.LVM_GETITEMW, 0, ref lvItemImageMask); if (isHot || (UInt32)lvItemImageMask.state == (2 << 12)) { res = User32.SendMessage(this._ShellViewEx.LVHandle, MSG.LVM_GETITEMW, 0, ref lvItem); var checkboxOffsetH = 14; var checkboxOffsetV = 2; if (this._ShellViewEx.View == ShellViewStyle.Tile || this._ShellViewEx.View == ShellViewStyle.SmallIcon) { checkboxOffsetH = 2; } if (this._ShellViewEx.View == ShellViewStyle.Tile) { checkboxOffsetV = 5; } CheckBoxRenderer.DrawCheckBox(g, new Point(iconBounds.Left + checkboxOffsetH, iconBounds.Top + checkboxOffsetV), lvItem.state != 0 ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal : System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); } } } if (sho.OverlayIconIndex > 0) { if (this._CurrentSize > 180) { this._Jumbo.DrawOverlay(hdc, sho.OverlayIconIndex, new Point(iconBounds.Left, iconBounds.Bottom - (this._ShellViewEx.View == ShellViewStyle.Tile ? 5 : 0) - this._CurrentSize / 3), this._CurrentSize / 3); } else if (this._CurrentSize > 64) { this._Extra.DrawOverlay(hdc, sho.OverlayIconIndex, new Point(iconBounds.Left + 10 - (this._ShellViewEx.View == ShellViewStyle.Tile ? 5 : 0), iconBounds.Bottom - 50)); } else { this._Large.DrawOverlay(hdc, sho.OverlayIconIndex, new Point(iconBounds.Left + 10 - (this._ShellViewEx.View == ShellViewStyle.Tile ? 5 : 0), iconBounds.Bottom - 32)); } } if (sho.ShieldedIconIndex > 0) { if (this._CurrentSize > 180) { this._Jumbo.DrawIcon(hdc, sho.ShieldedIconIndex, new Point(iconBounds.Right - this._CurrentSize / 3 - 3, iconBounds.Bottom - this._CurrentSize / 3), this._CurrentSize / 3); } else if (this._CurrentSize > 64) { this._Extra.DrawIcon(hdc, sho.ShieldedIconIndex, new Point(iconBounds.Right - 43, iconBounds.Bottom - 50)); } else { this._Large.DrawIcon(hdc, sho.ShieldedIconIndex, new Point(iconBounds.Right - 33, iconBounds.Bottom - 32)); } } if (sho.IsShared) { if (this._CurrentSize > 180) { this._Jumbo.DrawIcon(hdc, this._SharedIconIndex, new Point(iconBounds.Right - this._CurrentSize / 3, iconBounds.Bottom - this._CurrentSize / 3), this._CurrentSize / 3); } else if (this._CurrentSize > 64) { this._Extra.DrawIcon(hdc, this._SharedIconIndex, new Point(iconBounds.Right - 40, iconBounds.Bottom - 50)); } else { this._Large.DrawIcon(hdc, this._SharedIconIndex, new Point(iconBounds.Right - 30, iconBounds.Bottom - 32)); } } IListItemEx badge = this.GetBadgeForPath(sho.ParsingName); if (badge != null) { var badgeIco = badge.GetHBitmap(this._CurrentSize, false, false, true); Gdi32.ConvertPixelByPixel(badgeIco, out width, out height); Gdi32.NativeDraw(hdc, badgeIco, iconBounds.Left + (iconBounds.Right - iconBounds.Left - _CurrentSize) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - _CurrentSize) / 2, _CurrentSize, isGhosted); Gdi32.DeleteObject(badgeIco); badge.Dispose(); } if (this._ShellViewEx.View == ShellViewStyle.Tile) { var lvi = new LVITEMINDEX(); lvi.iItem = index; lvi.iGroup = this._ShellViewEx.GetGroupIndex(index); var lableBounds = new User32.RECT() { Left = 2 }; User32.SendMessage(this._ShellViewEx.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref lableBounds); using (var g = Graphics.FromHdc(hdc)) { var lblrectTiles = new RectangleF(lableBounds.Left, iconBounds.Top + 6, lableBounds.Right - lableBounds.Left, 15); if (this._ShellViewEx.RequestedCurrentLocation.ParsingName.Equals(KnownFolders.Computer.ParsingName) && (sho.IsDrive || sho.IsNetworkPath)) { var fmt = new StringFormat(); fmt.Trimming = StringTrimming.EllipsisCharacter; fmt.Alignment = StringAlignment.Center; fmt.Alignment = StringAlignment.Near; fmt.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox; fmt.LineAlignment = StringAlignment.Center; this.DrawComputerTiledModeView(sho, g, lblrectTiles, fmt); } } } } else { sho.IsThumbnailLoaded = true; Int32 width = 0, height = 0; if ((sho.IconType & IExtractIconPWFlags.GIL_PERCLASS) == IExtractIconPWFlags.GIL_PERCLASS) { var hIconExe = sho.GetHBitmap(this._CurrentSize, false); if (hIconExe != IntPtr.Zero) { sho.IsIconLoaded = true; Gdi32.ConvertPixelByPixel(hIconExe, out width, out height); Gdi32.NativeDraw(hdc, hIconExe, iconBounds.Left + (iconBounds.Right - iconBounds.Left - this._CurrentSize) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - this._CurrentSize) / 2, this._CurrentSize, isGhosted); Gdi32.DeleteObject(hIconExe); } } else if ((sho.IconType & IExtractIconPWFlags.GIL_PERINSTANCE) == IExtractIconPWFlags.GIL_PERINSTANCE) { if (!sho.IsIconLoaded) { /* * if (sho.IsNetworkPath || this._ShellViewEx.IsSearchNavigating) { * Task.Run(() => { * this._IconsForRetreval.Enqueue(index); * }); * } else { * Task.Run(() => { * this._IconsForRetreval.Enqueue(index); * }); * } */ //Task.Run(() => { this._IconsForRetreval.Enqueue(index); //}); this._Small.DrawIcon(hdc, this._ExeFallBackIndex, new Point(iconBounds.Left + (iconBounds.Right - iconBounds.Left - this._CurrentSize) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - this._CurrentSize) / 2)); } else { var hIconExe = sho.GetHBitmap(this._CurrentSize, false); if (hIconExe != IntPtr.Zero) { sho.IsIconLoaded = true; Gdi32.ConvertPixelByPixel(hIconExe, out width, out height); Gdi32.NativeDraw(hdc, hIconExe, iconBounds.Left + (iconBounds.Right - iconBounds.Left - this._CurrentSize) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - this._CurrentSize) / 2, this._CurrentSize, isGhosted); Gdi32.DeleteObject(hIconExe); } } } if (sho.OverlayIconIndex > 0) { this._Small.DrawOverlay(hdc, sho.OverlayIconIndex, new Point(iconBounds.Left, iconBounds.Bottom - 16)); } if (sho.ShieldedIconIndex > 0) { this._Small.DrawIcon(hdc, sho.ShieldedIconIndex, new Point(iconBounds.Right - 9, iconBounds.Bottom - 10), 10); } if (sho.IsShared) { this._Small.DrawIcon(hdc, this._SharedIconIndex, new Point(iconBounds.Right - 9, iconBounds.Bottom - 16)); } IListItemEx badge = this.GetBadgeForPath(sho.ParsingName); if (badge != null) { var badgeIco = badge.GetHBitmap(16, false, false, true); Gdi32.ConvertPixelByPixel(badgeIco, out width, out height); Gdi32.NativeDraw(hdc, badgeIco, iconBounds.Left, iconBounds.Top, 16, isGhosted); Gdi32.DeleteObject(badgeIco); } } }
void DelayTimer_Tick(object sender, EventArgs e) { _DelayTimer.Stop(); var t = new Thread(() => { var clonedCurrentItem = this.CurrentItem.Clone(); var tooltip = clonedCurrentItem.ToolTipText; if (String.IsNullOrEmpty(tooltip) && Type == 1) { Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)(this.Hide)); return; } Contents = Type == 0 ? $"{clonedCurrentItem.DisplayName}\r\n{clonedCurrentItem.ToolTipText}" : clonedCurrentItem.ToolTipText; RaisePropertyChanged("Contents"); // BE-557: clonedCurrentItem.GetPropertyValue returned VT_EMPTY, edge case included to handle this var perceivedTypeProperty = clonedCurrentItem.GetPropertyValue( SystemProperties.PerceivedType, typeof(PerceivedType)); if (perceivedTypeProperty.VarType != VarEnum.VT_EMPTY && ((PerceivedType)perceivedTypeProperty.Value) == PerceivedType.Image && !clonedCurrentItem.IsFolder) { var image = clonedCurrentItem.ThumbnailSource( 350, ShellThumbnailFormatOption.Default, ShellThumbnailRetrievalOption.Default); image.Freeze(); this.Image = image; RaisePropertyChanged("Image"); this.FileNameWidth = this.Image.Width - 110; RaisePropertyChanged("FileNameWidth"); try { var ratingValue = clonedCurrentItem.GetPropertyValue(MediaProperties.Rating, typeof(Double)).Value; var rating = ratingValue == null ? 0 : Convert.ToDouble(ratingValue) / 20D; this.Rating = rating; RaisePropertyChanged("Rating"); this.Dimentions = ((Math.Ceiling( Convert.ToDouble(clonedCurrentItem.GetPropertyValue(SystemProperties.FileSize, typeof(double)).Value)) / 1024).ToString("# ### ### ##0") + " KB (" + clonedCurrentItem.GetPropertyValue(MediaProperties.Dimensions, typeof(String)).Value.ToString() + " px )").Trim(); RaisePropertyChanged("Dimentions"); } catch (NullReferenceException) { } this.FileName = Path.GetFileName(clonedCurrentItem.ParsingName)?.Trim(); RaisePropertyChanged("FileName"); } else { var image = clonedCurrentItem.ThumbnailSource( 64, ShellThumbnailFormatOption.Default, ShellThumbnailRetrievalOption.Default); image.Freeze(); this.Image = image; RaisePropertyChanged("Image"); } clonedCurrentItem.Dispose(); Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)(() => { var lvi = new LVITEMINDEX(); lvi.iItem = this.ItemIndex; lvi.iGroup = this._View.GetGroupIndex(this.ItemIndex); var bounds = new User32.RECT(); User32.SendMessage(this._View.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref bounds); var rect = new System.Drawing.Rectangle(bounds.Left, bounds.Top, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); var posm = User32.GetCursorPosition(); var mousePos = this._View.PointToClient(posm); var isInsideItem = rect.Contains(mousePos); if (isInsideItem) { this.Show(); } else { this.Hide(); } })); }); t.SetApartmentState(ApartmentState.STA); t.Start(); }