示例#1
0
        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);
        }
示例#3
0
        // Helper to generate the image - I grabbed this off Google
        // somewhere. -- Chris Bordeman [email protected]
        private static BitmapSource CaptureScreen(Visual target, FlowDirection flowDirection)
        {
            if (target == null)
            {
                return(null);
            }

            var dpiX = DpiHelper.DpiX;
            var dpiY = DpiHelper.DpiY;

            var bounds    = VisualTreeHelper.GetDescendantBounds(target);
            var dpiBounds = DpiHelper.LogicalRectToDevice(bounds);

            var pixelWidth  = (int)Math.Ceiling(dpiBounds.Width);
            var pixelHeight = (int)Math.Ceiling(dpiBounds.Height);

            if (pixelWidth < 0 || pixelHeight < 0)
            {
                return(null);
            }

            var rtb = new RenderTargetBitmap(pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Pbgra32);

            var dv = new DrawingVisual();

            using (var ctx = dv.RenderOpen())
            {
                var vb = new VisualBrush(target);
                if (flowDirection == FlowDirection.RightToLeft)
                {
                    var transformGroup = new TransformGroup();
                    transformGroup.Children.Add(new ScaleTransform(-1, 1));
                    transformGroup.Children.Add(new TranslateTransform(bounds.Size.Width - 1, 0));
                    ctx.PushTransform(transformGroup);
                }
                ctx.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
            }

            rtb.Render(dv);

            return(rtb);
        }
示例#4
0
        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));
        }