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) { 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); }
void UpdateTaskbarThumbnailRect() { var BrowserRect = new WinAPI.RECT(); WinAPI.GetWindowRect(this.Handle, out BrowserRect); var _rp = new Point(); _rp.X = BrowserRect.left; _rp.Y = BrowserRect.top; WinAPI.ScreenToClient(this.FormParent.Handle, out _rp); BrowserRect.right = _rp.X + (BrowserRect.right - BrowserRect.left); BrowserRect.bottom = _rp.Y + (BrowserRect.bottom - BrowserRect.top); BrowserRect.left = _rp.X; BrowserRect.top = _rp.Y; var _g = GCHandle.Alloc(BrowserRect, GCHandleType.Pinned); IntPtr _p = _g.AddrOfPinnedObject(); TaskbarList.SetThumbnailClip(this.FormParent.Handle, _p); _g.Free(); }