private HRESULT _UpdateThumbnailClipping(bool attached) { Assert.IsNotNull(_window); RefRECT interopRc = null; if (attached && ThumbnailClipMargin != _EmptyThickness) { var margin = ThumbnailClipMargin; var physicalClientRc = NativeMethods.GetClientRect(_hwndSource.Handle); var logicalClientRc = DpiHelper.DeviceRectToLogical(new Rect(physicalClientRc.Left, physicalClientRc.Top, physicalClientRc.Width, physicalClientRc.Height)); if (margin.Left + margin.Right >= logicalClientRc.Width || margin.Top + margin.Bottom >= logicalClientRc.Height) { interopRc = new RefRECT(0, 0, 0, 0); } else { var logicalClip = new Rect(margin.Left, margin.Top, logicalClientRc.Width - margin.Left - margin.Right, logicalClientRc.Height - margin.Top - margin.Bottom); var physicalClip = DpiHelper.LogicalRectToDevice(logicalClip); interopRc = new RefRECT((int)physicalClip.Left, (int)physicalClip.Top, (int)physicalClip.Right, (int)physicalClip.Bottom); } } var hr = _taskbarList.SetThumbnailClip(_hwndSource.Handle, interopRc); Assert.IsTrue(hr.Succeeded); return(hr); }
private HRESULT _UpdateThumbnailClipping(bool attached) { Assert.IsNotNull(_window); RefRECT interopRc = null; if (attached && ThumbnailClipMargin != _EmptyThickness) { Thickness margin = ThumbnailClipMargin; // Use the native GetClientRect. Window.ActualWidth and .ActualHeight include the non-client areas. RECT physicalClientRc = NativeMethods.GetClientRect(_hwndSource.Handle); Rect logicalClientRc = DpiHelper.DeviceRectToLogical(new Rect(physicalClientRc.Left, physicalClientRc.Top, physicalClientRc.Width, physicalClientRc.Height)); // Crop the clipping to ensure that the margin doesn't overlap itself. if (margin.Left + margin.Right >= logicalClientRc.Width || margin.Top + margin.Bottom >= logicalClientRc.Height) { interopRc = new RefRECT(0, 0, 0, 0); } else { Rect logicalClip = new Rect(margin.Left, margin.Top, logicalClientRc.Width - margin.Left - margin.Right, logicalClientRc.Height - margin.Top - margin.Bottom); Rect physicalClip = DpiHelper.LogicalRectToDevice(logicalClip); interopRc = new RefRECT((int)physicalClip.Left, (int)physicalClip.Top, (int)physicalClip.Right, (int)physicalClip.Bottom); } } // This will fail in the interop layer if called too early. HRESULT hr = _taskbarList.SetThumbnailClip(_hwndSource.Handle, interopRc); Assert.IsTrue(hr.Succeeded); return(hr); }
private HRESULT _UpdateThumbnailClipping(bool attached) { RefRECT prcClip = null; if (attached && this.ThumbnailClipMargin != TaskbarItemInfo._EmptyThickness) { Thickness thumbnailClipMargin = this.ThumbnailClipMargin; RECT clientRect = NativeMethods.GetClientRect(this._hwndSource.Handle); Rect rect = DpiHelper.DeviceRectToLogical(new Rect((double)clientRect.Left, (double)clientRect.Top, (double)clientRect.Width, (double)clientRect.Height)); if (thumbnailClipMargin.Left + thumbnailClipMargin.Right >= rect.Width || thumbnailClipMargin.Top + thumbnailClipMargin.Bottom >= rect.Height) { prcClip = new RefRECT(0, 0, 0, 0); } else { Rect logicalRectangle = new Rect(thumbnailClipMargin.Left, thumbnailClipMargin.Top, rect.Width - thumbnailClipMargin.Left - thumbnailClipMargin.Right, rect.Height - thumbnailClipMargin.Top - thumbnailClipMargin.Bottom); Rect rect2 = DpiHelper.LogicalRectToDevice(logicalRectangle); prcClip = new RefRECT((int)rect2.Left, (int)rect2.Top, (int)rect2.Right, (int)rect2.Bottom); } } return(this._taskbarList.SetThumbnailClip(this._hwndSource.Handle, prcClip)); }