Ejemplo n.º 1
0
        void ApplyRegion(Rect wndRect)
        {
            if (!this.CanTransform())
            {
                return;
            }

            wndRect = new Rect(
                this.TransformFromDeviceDPI(wndRect.TopLeft),
                this.TransformFromDeviceDPI(wndRect.Size));

            _lastApplyRect = wndRect;

            if (PresentationSource.FromVisual(this) == null)
            {
                return;
            }


            if (_dockingManager != null)
            {
                List <Rect> otherRects = new List <Rect>();

                foreach (Window fl in Window.GetWindow(_dockingManager).OwnedWindows)
                {
                    //not with myself!
                    if (fl == this)
                    {
                        continue;
                    }

                    if (!fl.IsVisible)
                    {
                        continue;
                    }

                    //Issue 11545, thx to SrdjanPolic
                    Rect flRect = new Rect(
                        PointFromScreen(new Point(fl.Left, fl.Top)),
                        PointFromScreen(new Point(fl.Left + fl.RestoreBounds.Width, fl.Top + fl.RestoreBounds.Height)));

                    if (flRect.IntersectsWith(wndRect) && fl.AllowsTransparency == false)
                    {
                        otherRects.Add(Rect.Intersect(flRect, wndRect));
                    }

                    //Rect flRect = new Rect(
                    //    PointFromScreen(new Point(fl.Left, fl.Top)),
                    //    PointFromScreen(new Point(fl.Left + fl.Width, fl.Top + fl.Height)));

                    //if (flRect.IntersectsWith(wndRect))
                    //    otherRects.Add(Rect.Intersect(flRect, wndRect));
                }

                IntPtr hDestRegn = InteropHelper.CreateRectRgn(
                    (int)wndRect.Left,
                    (int)wndRect.Top,
                    (int)wndRect.Right,
                    (int)wndRect.Bottom);

                foreach (Rect otherRect in otherRects)
                {
                    IntPtr otherWin32Rect = InteropHelper.CreateRectRgn(
                        (int)otherRect.Left,
                        (int)otherRect.Top,
                        (int)otherRect.Right,
                        (int)otherRect.Bottom);

                    InteropHelper.CombineRgn(hDestRegn, hDestRegn, otherWin32Rect, (int)InteropHelper.CombineRgnStyles.RGN_DIFF);
                }


                InteropHelper.SetWindowRgn(new WindowInteropHelper(this).Handle, hDestRegn, true);
            }
        }
        private void ApplyRegion(Rect wndRect)
        {
            if (!this.CanTransform())
            {
                return;
            }

            wndRect = new Rect(
                this.TransformFromDeviceDPI(wndRect.TopLeft),
                this.TransformFromDeviceDPI(wndRect.Size));

            _lastApplyRect = wndRect;

            if (PresentationSource.FromVisual(this) == null)
            {
                return;
            }


            if (_dockingManager != null)
            {
                var otherRects = new List <Rect>();

                foreach (Window fl in GetWindow(_dockingManager).OwnedWindows)
                {
                    //not with myself!
                    if (fl == this)
                    {
                        continue;
                    }

                    if (!fl.IsVisible)
                    {
                        continue;
                    }

                    var flRect = new Rect(
                        PointFromScreen(new Point(fl.Left, fl.Top)),
                        PointFromScreen(new Point(fl.Left + fl.Width, fl.Top + fl.Height)));

                    if (flRect.IntersectsWith(wndRect))
                    {
                        otherRects.Add(Rect.Intersect(flRect, wndRect));
                    }
                }

                var hDestRegn = InteropHelper.CreateRectRgn(
                    (int)wndRect.Left,
                    (int)wndRect.Top,
                    (int)wndRect.Right,
                    (int)wndRect.Bottom);

                foreach (var otherRect in otherRects)
                {
                    var otherWin32Rect = InteropHelper.CreateRectRgn(
                        (int)otherRect.Left,
                        (int)otherRect.Top,
                        (int)otherRect.Right,
                        (int)otherRect.Bottom);

                    InteropHelper.CombineRgn(hDestRegn, hDestRegn, otherWin32Rect,
                                             (int)InteropHelper.CombineRgnStyles.RGN_DIFF);
                }


                InteropHelper.SetWindowRgn(new WindowInteropHelper(this).Handle, hDestRegn, true);
            }
        }