예제 #1
0
    private IntPtr _HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled)
    {
        IntPtr intPtr = IntPtr.Zero;

        handled = false;
        if (Utility.IsOSVistaOrNewer && this._chromeInfo.GlassFrameThickness != default(Thickness) && this._isGlassEnabled)
        {
            handled = NativeMethods.DwmDefWindowProc(this._hwnd, uMsg, wParam, lParam, out intPtr);
        }
        if (IntPtr.Zero == intPtr)
        {
            Point point           = new Point((double)Utility.GET_X_LPARAM(lParam), (double)Utility.GET_Y_LPARAM(lParam));
            Rect  deviceRectangle = this._GetWindowRect();
            HT    ht = this._HitTestNca(DpiHelper.DeviceRectToLogical(deviceRectangle), DpiHelper.DevicePixelsToLogical(point));
            if (ht != HT.CLIENT)
            {
                Point point2 = point;
                point2.Offset(-deviceRectangle.X, -deviceRectangle.Y);
                point2 = DpiHelper.DevicePixelsToLogical(point2);
                IInputElement inputElement = this._window.InputHitTest(point2);
                if (inputElement != null && WindowChrome.GetIsHitTestVisibleInChrome(inputElement))
                {
                    ht = HT.CLIENT;
                }
            }
            handled = true;
            intPtr  = new IntPtr((int)ht);
        }
        return(intPtr);
    }
예제 #2
0
        private void _InitializeCaptionButtonLocation()
        {
            if (!Utility.IsOSVistaOrNewer || !Standard.NativeMethods.IsThemeActive())
            {
                this._LegacyInitializeCaptionButtonLocation();
                return;
            }
            TITLEBARINFOEX tITLEBARINFOEX = new TITLEBARINFOEX()
            {
                cbSize = Marshal.SizeOf(typeof(TITLEBARINFOEX))
            };
            TITLEBARINFOEX structure = tITLEBARINFOEX;
            IntPtr         intPtr    = Marshal.AllocHGlobal(structure.cbSize);

            try
            {
                Marshal.StructureToPtr(structure, intPtr, false);
                Standard.NativeMethods.ShowWindow(this._messageHwnd.Handle, SW.SHOWNA);
                Standard.NativeMethods.SendMessage(this._messageHwnd.Handle, WM.GETTITLEBARINFOEX, IntPtr.Zero, intPtr);
                structure = (TITLEBARINFOEX)Marshal.PtrToStructure(intPtr, typeof(TITLEBARINFOEX));
            }
            finally
            {
                Standard.NativeMethods.ShowWindow(this._messageHwnd.Handle, SW.HIDE);
                Utility.SafeFreeHGlobal(ref intPtr);
            }
            RECT rECT       = RECT.Union(structure.rgrect_CloseButton, structure.rgrect_MinimizeButton);
            RECT windowRect = Standard.NativeMethods.GetWindowRect(this._messageHwnd.Handle);
            Rect rect       = new Rect((double)(rECT.Left - windowRect.Width - windowRect.Left), (double)(rECT.Top - windowRect.Top), (double)rECT.Width, (double)rECT.Height);

            this.WindowCaptionButtonsLocation = DpiHelper.DeviceRectToLogical(rect);
        }
예제 #3
0
        private IntPtr _HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled)
        {
            IntPtr zero = IntPtr.Zero;

            handled = false;
            if (Utility.IsOSVistaOrNewer)
            {
                if (this._chromeInfo.GlassFrameThickness != new Thickness() && this._isGlassEnabled)
                {
                    handled = Standard.NativeMethods.DwmDefWindowProc(this._hwnd, uMsg, wParam, lParam, out zero);
                }
            }
            if (IntPtr.Zero == zero)
            {
                Point point = new Point((double)Utility.GET_X_LPARAM(lParam), (double)Utility.GET_Y_LPARAM(lParam));
                Rect  rect  = this._GetWindowRect();
                HT    hT    = this._HitTestNca(DpiHelper.DeviceRectToLogical(rect), DpiHelper.DevicePixelsToLogical(point));
                if (hT != HT.CLIENT)
                {
                    Point logical = point;
                    logical.Offset(-rect.X, -rect.Y);
                    logical = DpiHelper.DevicePixelsToLogical(logical);
                    IInputElement inputElement = this._window.InputHitTest(logical);
                    if (inputElement != null && WindowChrome.GetIsHitTestVisibleInChrome(inputElement))
                    {
                        hT = HT.CLIENT;
                    }
                }
                handled = true;
                zero    = new IntPtr((int)hT);
            }
            return(zero);
        }
예제 #4
0
        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);
        }
예제 #5
0
        private IntPtr _HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled)
        {
            var zero = IntPtr.Zero;

            handled = false;
            if (Utility.IsOSVistaOrNewer && _chromeInfo.GlassFrameThickness != new Thickness() && _isGlassEnabled)
            {
                handled = NativeMethods.DwmDefWindowProc(_hwnd, uMsg, wParam, lParam, out zero);
            }
            if (!(IntPtr.Zero == zero))
            {
                return(zero);
            }
            var devicePoint     = new Point(Utility.GET_X_LPARAM(lParam), Utility.GET_Y_LPARAM(lParam));
            var deviceRectangle = _GetWindowRect();
            var cLIENT          = _HitTestNca(DpiHelper.DeviceRectToLogical(deviceRectangle),
                                              DpiHelper.DevicePixelsToLogical(devicePoint));

            if (cLIENT != HT.CLIENT)
            {
                var point2 = devicePoint;
                point2.Offset(-deviceRectangle.X, -deviceRectangle.Y);
                point2 = DpiHelper.DevicePixelsToLogical(point2);
                var inputElement = _window.InputHitTest(point2);
                if (inputElement != null && WindowChrome.GetIsHitTestVisibleInChrome(inputElement))
                {
                    cLIENT = HT.CLIENT;
                }
            }
            handled = true;
            return(new IntPtr((int)cLIENT));
        }
예제 #6
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);
        }
예제 #7
0
        private void _InitializeCaptionButtonLocation()
        {
            if (!Utility.IsOSVistaOrNewer || !NativeMethods.IsThemeActive())
            {
                this._LegacyInitializeCaptionButtonLocation();
                return;
            }
            TITLEBARINFOEX titlebarinfoex = new TITLEBARINFOEX
            {
                cbSize = Marshal.SizeOf(typeof(TITLEBARINFOEX))
            };
            IntPtr intPtr = Marshal.AllocHGlobal(titlebarinfoex.cbSize);

            try
            {
                Marshal.StructureToPtr(titlebarinfoex, intPtr, false);
                NativeMethods.ShowWindow(this._messageHwnd.Handle, SW.SHOW);
                NativeMethods.SendMessage(this._messageHwnd.Handle, WM.GETTITLEBARINFOEX, IntPtr.Zero, intPtr);
                titlebarinfoex = (TITLEBARINFOEX)Marshal.PtrToStructure(intPtr, typeof(TITLEBARINFOEX));
            }
            finally
            {
                NativeMethods.ShowWindow(this._messageHwnd.Handle, SW.HIDE);
                Utility.SafeFreeHGlobal(ref intPtr);
            }
            RECT rect            = RECT.Union(titlebarinfoex.rgrect_CloseButton, titlebarinfoex.rgrect_MinimizeButton);
            RECT windowRect      = NativeMethods.GetWindowRect(this._messageHwnd.Handle);
            Rect deviceRectangle = new Rect((double)(rect.Left - windowRect.Width - windowRect.Left), (double)(rect.Top - windowRect.Top), (double)rect.Width, (double)rect.Height);
            Rect windowCaptionButtonsLocation = DpiHelper.DeviceRectToLogical(deviceRectangle);

            this.WindowCaptionButtonsLocation = windowCaptionButtonsLocation;
        }
예제 #8
0
        private void _InitializeCaptionButtonLocation()
        {
            // There is a completely different way to do this on XP.
            if (!Utility.IsOSVistaOrNewer || !NativeMethods.IsThemeActive())
            {
                _LegacyInitializeCaptionButtonLocation();
                return;
            }

            var tbix = new TITLEBARINFOEX {
                cbSize = Marshal.SizeOf(typeof(TITLEBARINFOEX))
            };
            IntPtr lParam = Marshal.AllocHGlobal(tbix.cbSize);

            try
            {
                Marshal.StructureToPtr(tbix, lParam, false);
                // This might flash a window in the taskbar while being calculated.
                // WM_GETTITLEBARINFOEX doesn't work correctly unless the window is visible while processing.
                // use SW.SHOWNA instead SW.SHOW to avoid some brief flashing when launched the window
                NativeMethods.ShowWindow(_messageHwnd.Handle, SW.SHOWNA);
                NativeMethods.SendMessage(_messageHwnd.Handle, WM.GETTITLEBARINFOEX, IntPtr.Zero, lParam);
                tbix = (TITLEBARINFOEX)Marshal.PtrToStructure(lParam, typeof(TITLEBARINFOEX));
            }
            finally
            {
                NativeMethods.ShowWindow(_messageHwnd.Handle, SW.HIDE);
                Utility.SafeFreeHGlobal(ref lParam);
            }

            // TITLEBARINFOEX has information relative to the screen.  We need to convert the containing rect
            // to instead be relative to the top-right corner of the window.
            RECT rcAllCaptionButtons = RECT.Union(tbix.rgrect_CloseButton, tbix.rgrect_MinimizeButton);

            // For all known themes, the RECT for the maximize box shouldn't add anything to the union of the minimize and close boxes.
            Assert.AreEqual(rcAllCaptionButtons, RECT.Union(rcAllCaptionButtons, tbix.rgrect_MaximizeButton));

            RECT rcWindow = NativeMethods.GetWindowRect(_messageHwnd.Handle);

            // Reorient the Top/Right to be relative to the top right edge of the Window.
            var deviceCaptionLocation = new Rect(
                rcAllCaptionButtons.Left - rcWindow.Width - rcWindow.Left,
                rcAllCaptionButtons.Top - rcWindow.Top,
                rcAllCaptionButtons.Width,
                rcAllCaptionButtons.Height);

            Rect logicalCaptionLocation = DpiHelper.DeviceRectToLogical(deviceCaptionLocation);

            WindowCaptionButtonsLocation = logicalCaptionLocation;
        }
        private void _LegacyInitializeCaptionButtonLocation()
        {
            // This calculation isn't quite right, but it's pretty close.
            // I expect this is good enough for the scenarios where this is expected to be used.
            int captionX = NativeMethods.GetSystemMetrics(SM.CXSIZE);
            int captionY = NativeMethods.GetSystemMetrics(SM.CYSIZE);

            int frameX = NativeMethods.GetSystemMetrics(SM.CXSIZEFRAME) + NativeMethods.GetSystemMetrics(SM.CXEDGE);
            int frameY = NativeMethods.GetSystemMetrics(SM.CYSIZEFRAME) + NativeMethods.GetSystemMetrics(SM.CYEDGE);

            Rect deviceCaptionLocation = new Rect(0.0, 0.0, (captionX * 3), captionY);

            deviceCaptionLocation.Offset(-frameX - deviceCaptionLocation.Width, frameY);
            Rect logicalCaptionLocation = DpiHelper.DeviceRectToLogical(deviceCaptionLocation);

            WindowCaptionButtonsLocation = logicalCaptionLocation;
        }
예제 #10
0
        private void _FixupFrameworkIssues()
        {
            if (!Utility.IsPresentationFrameworkVersionLessThan4)
            {
                return;
            }
            if (this._window.Template == null)
            {
                return;
            }
            if (VisualTreeHelper.GetChildrenCount(this._window) == 0)
            {
                this._window.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new WindowChromeWorker._Action(this._FixupFrameworkIssues));
                return;
            }
            FrameworkElement child      = (FrameworkElement)VisualTreeHelper.GetChild(this._window, 0);
            RECT             windowRect = Standard.NativeMethods.GetWindowRect(this._hwnd);
            RECT             rECT       = this._GetAdjustedWindowRect(windowRect);
            Rect             logical    = DpiHelper.DeviceRectToLogical(new Rect((double)windowRect.Left, (double)windowRect.Top, (double)windowRect.Width, (double)windowRect.Height));
            Rect             rect       = DpiHelper.DeviceRectToLogical(new Rect((double)rECT.Left, (double)rECT.Top, (double)rECT.Width, (double)rECT.Height));
            Thickness        thickness  = new Thickness(logical.Left - rect.Left, logical.Top - rect.Top, rect.Right - logical.Right, rect.Bottom - logical.Bottom);

            if (child != null)
            {
                child.Margin = new Thickness(0, 0, -(thickness.Left + thickness.Right), -(thickness.Top + thickness.Bottom));
            }
            if (child != null)
            {
                if (this._window.FlowDirection != FlowDirection.RightToLeft)
                {
                    child.RenderTransform = null;
                }
                else
                {
                    child.RenderTransform = new MatrixTransform(1, 0, 0, 1, -(thickness.Left + thickness.Right), 0);
                }
            }
            if (!this._isFixedUp)
            {
                this._hasUserMovedWindow   = false;
                this._window.StateChanged += new EventHandler(this._FixupRestoreBounds);
                this._isFixedUp            = true;
            }
        }
예제 #11
0
        private IntPtr _HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled)
        {
            var mousePosScreen = new Point(Utility.GET_X_LPARAM(lParam), Utility.GET_Y_LPARAM(lParam));
            var windowPosition = _GetWindowRect();
            var mousePosWindow = mousePosScreen;

            mousePosWindow.Offset(-windowPosition.X, -windowPosition.Y);
            mousePosWindow = DpiHelper.DevicePixelsToLogical(mousePosWindow);

            var inputElement = _window.InputHitTest(mousePosWindow);

            if (inputElement != null)
            {
                if (WindowChrome.GetIsHitTestVisibleInChrome(inputElement))
                {
                    handled = true;
                    return(new IntPtr((int)HT.CLIENT));
                }
                var direction = WindowChrome.GetResizeGripDirection(inputElement);
                if (direction != ResizeGripDirection.None)
                {
                    handled = true;
                    return(new IntPtr((int)_GetHTFromResizeGripDirection(direction)));
                }
            }

            if (_chromeInfo.UseAeroCaptionButtons)
            {
                if (Utility.IsOSVistaOrNewer && _chromeInfo.GlassFrameThickness != default(Thickness) && _isGlassEnabled)
                {
                    IntPtr lRet;
                    handled = NativeMethods.DwmDefWindowProc(_hwnd, uMsg, wParam, lParam, out lRet);
                    if (IntPtr.Zero != lRet)
                    {
                        return(lRet);
                    }
                }
            }
            var ht = _HitTestNca(DpiHelper.DeviceRectToLogical(windowPosition), DpiHelper.DevicePixelsToLogical(mousePosScreen));

            handled = true;
            return(new IntPtr((int)ht));
        }
        private IntPtr _HandleNCHITTEST(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled)
        {
            // We always want to handle hit-testing
            handled = true;

            var dpi = this.AssociatedObject.GetDpi();

            // Let the system know if we consider the mouse to be in our effective non-client area.
            var mousePosScreen = Utility.GetPoint(lParam); //new Point(Utility.GET_X_LPARAM(lParam), Utility.GET_Y_LPARAM(lParam));
            var windowPosition = this._GetWindowRect();

            var mousePosWindow = mousePosScreen;

            mousePosWindow.Offset(-windowPosition.X, -windowPosition.Y);
            mousePosWindow = DpiHelper.DevicePixelsToLogical(mousePosWindow, dpi.DpiScaleX, dpi.DpiScaleY);

            var ht = this._HitTestNca(DpiHelper.DeviceRectToLogical(windowPosition, dpi.DpiScaleX, dpi.DpiScaleY),
                                      DpiHelper.DevicePixelsToLogical(mousePosScreen, dpi.DpiScaleX, dpi.DpiScaleY));

            if (ht != HT.CLIENT ||
                this.AssociatedObject.ResizeMode == ResizeMode.CanResizeWithGrip)
            {
                // If the app is asking for content to be treated as client then that takes precedence over _everything_, even DWM caption buttons.
                // This allows apps to set the glass frame to be non-empty, still cover it with WPF content to hide all the glass,
                // yet still get DWM to draw a drop shadow.
                var inputElement = this.AssociatedObject.InputHitTest(mousePosWindow);
                if (inputElement is not null)
                {
                    if (WindowChrome.GetIsHitTestVisibleInChrome(inputElement))
                    {
                        return(new IntPtr((int)HT.CLIENT));
                    }

                    var direction = WindowChrome.GetResizeGripDirection(inputElement);
                    if (direction != ResizeGripDirection.None)
                    {
                        return(new IntPtr((int)this._GetHTFromResizeGripDirection(direction)));
                    }
                }
            }

            return(new IntPtr((int)ht));
        }
        private IntPtr _HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled)
        {
            DpiScale dpi             = this._window.GetDpi();
            Point    point           = new Point((double)Utility.GET_X_LPARAM(lParam), (double)Utility.GET_Y_LPARAM(lParam));
            Rect     deviceRectangle = this._GetWindowRect();
            Point    point2          = point;

            point2.Offset(-deviceRectangle.X, -deviceRectangle.Y);
            point2 = DpiHelper.DevicePixelsToLogical(point2, dpi.DpiScaleX, dpi.DpiScaleY);
            IInputElement inputElement = this._window.InputHitTest(point2);

            if (inputElement != null)
            {
                if (WindowChrome.GetIsHitTestVisibleInChrome(inputElement))
                {
                    handled = true;
                    return(new IntPtr(1));
                }
                ResizeGripDirection resizeGripDirection = WindowChrome.GetResizeGripDirection(inputElement);
                if (resizeGripDirection != ResizeGripDirection.None)
                {
                    handled = true;
                    return(new IntPtr((int)this._GetHTFromResizeGripDirection(resizeGripDirection)));
                }
            }
            if (this._chromeInfo.UseAeroCaptionButtons && Utility.IsOSVistaOrNewer && this._chromeInfo.GlassFrameThickness != default(Thickness) && this._isGlassEnabled)
            {
                IntPtr intPtr;
                handled = NativeMethods.DwmDefWindowProc(this._hwnd, uMsg, wParam, lParam, out intPtr);
                if (IntPtr.Zero != intPtr)
                {
                    return(intPtr);
                }
            }
            HT value = this._HitTestNca(DpiHelper.DeviceRectToLogical(deviceRectangle, dpi.DpiScaleX, dpi.DpiScaleY), DpiHelper.DevicePixelsToLogical(point, dpi.DpiScaleX, dpi.DpiScaleY));

            handled = true;
            return(new IntPtr((int)value));
        }
예제 #14
0
 private void _FixupFrameworkIssues()
 {
     if (Utility.IsPresentationFrameworkVersionLessThan4 && _window.Template != null)
     {
         if (VisualTreeHelper.GetChildrenCount(_window) == 0)
         {
             _window.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new _Action(_FixupFrameworkIssues));
         }
         else
         {
             var child      = (FrameworkElement)VisualTreeHelper.GetChild(_window, 0);
             var windowRect = NativeMethods.GetWindowRect(_hwnd);
             var rect2      = _GetAdjustedWindowRect(windowRect);
             var rect3      = DpiHelper.DeviceRectToLogical(new Rect(windowRect.Left, windowRect.Top,
                                                                     windowRect.Width, windowRect.Height));
             var rect4 = DpiHelper.DeviceRectToLogical(
                 new Rect(rect2.Left, rect2.Top, rect2.Width, rect2.Height));
             var thickness = new Thickness(rect3.Left - rect4.Left, rect3.Top - rect4.Top,
                                           rect4.Right - rect3.Right, rect4.Bottom - rect3.Bottom);
             child.Margin = new Thickness(0.0, 0.0, -(thickness.Left + thickness.Right),
                                          -(thickness.Top + thickness.Bottom));
             if (_window.FlowDirection == FlowDirection.RightToLeft)
             {
                 child.RenderTransform =
                     new MatrixTransform(1.0, 0.0, 0.0, 1.0, -(thickness.Left + thickness.Right), 0.0);
             }
             else
             {
                 child.RenderTransform = null;
             }
             if (!_isFixedUp)
             {
                 _hasUserMovedWindow   = false;
                 _window.StateChanged += _FixupRestoreBounds;
                 _isFixedUp            = true;
             }
         }
     }
 }
예제 #15
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));
        }
예제 #16
0
        private void _InitializeCaptionButtonLocation()
        {
            if (!Utility.IsOSVistaOrNewer || !NativeMethods.IsThemeActive())
            {
                _LegacyInitializeCaptionButtonLocation();
                return;
            }
            var tbix = new TITLEBARINFOEX {
                cbSize = Marshal.SizeOf(typeof(TITLEBARINFOEX))
            };
            var lParam = Marshal.AllocHGlobal(tbix.cbSize);

            try
            {
                Marshal.StructureToPtr(tbix, lParam, false);

                NativeMethods.ShowWindow(_messageHwnd.Handle, SW.SHOW);
                NativeMethods.SendMessage(_messageHwnd.Handle, WM.GETTITLEBARINFOEX, IntPtr.Zero, lParam);
                tbix = (TITLEBARINFOEX)Marshal.PtrToStructure(lParam, typeof(TITLEBARINFOEX));
            }
            finally
            {
                NativeMethods.ShowWindow(_messageHwnd.Handle, SW.HIDE);
                Utility.SafeFreeHGlobal(ref lParam);
            }

            var rcAllCaptionButtons = RECT.Union(tbix.rgrect_CloseButton, tbix.rgrect_MinimizeButton);

            Assert.AreEqual(rcAllCaptionButtons, RECT.Union(rcAllCaptionButtons, tbix.rgrect_MaximizeButton));
            var rcWindow = NativeMethods.GetWindowRect(_messageHwnd.Handle);

            var deviceCaptionLocation = new Rect(rcAllCaptionButtons.Left - rcWindow.Width - rcWindow.Left, rcAllCaptionButtons.Top - rcWindow.Top,
                                                 rcAllCaptionButtons.Width, rcAllCaptionButtons.Height);
            var logicalCaptionLocation = DpiHelper.DeviceRectToLogical(deviceCaptionLocation);

            WindowCaptionButtonsLocation = logicalCaptionLocation;
        }
        private void _FixupTemplateIssues()
        {
            if (this._window.Template == null)
            {
                return;
            }
            if (VisualTreeHelper.GetChildrenCount(this._window) == 0)
            {
                this._window.VisualChildrenChanged += this.RetryFixupTemplateIssuesOnVisualChildrenAdded;
                return;
            }
            Thickness        margin           = default(Thickness);
            FrameworkElement frameworkElement = (FrameworkElement)VisualTreeHelper.GetChild(this._window, 0);

            if (this._chromeInfo.NonClientFrameEdges != NonClientFrameEdges.None)
            {
                if (Utility.IsFlagSet((int)this._chromeInfo.NonClientFrameEdges, 2))
                {
                    margin.Top -= SystemParameters.WindowResizeBorderThickness.Top;
                }
                if (Utility.IsFlagSet((int)this._chromeInfo.NonClientFrameEdges, 1))
                {
                    margin.Left -= SystemParameters.WindowResizeBorderThickness.Left;
                }
                if (Utility.IsFlagSet((int)this._chromeInfo.NonClientFrameEdges, 8))
                {
                    margin.Bottom -= SystemParameters.WindowResizeBorderThickness.Bottom;
                }
                if (Utility.IsFlagSet((int)this._chromeInfo.NonClientFrameEdges, 4))
                {
                    margin.Right -= SystemParameters.WindowResizeBorderThickness.Right;
                }
            }
            if (Utility.IsPresentationFrameworkVersionLessThan4)
            {
                DpiScale dpi        = this._window.GetDpi();
                RECT     windowRect = NativeMethods.GetWindowRect(this._hwnd);
                RECT     rect       = this._GetAdjustedWindowRect(windowRect);
                Rect     rect2      = DpiHelper.DeviceRectToLogical(new Rect((double)windowRect.Left, (double)windowRect.Top, (double)windowRect.Width, (double)windowRect.Height), dpi.DpiScaleX, dpi.DpiScaleY);
                Rect     rect3      = DpiHelper.DeviceRectToLogical(new Rect((double)rect.Left, (double)rect.Top, (double)rect.Width, (double)rect.Height), dpi.DpiScaleX, dpi.DpiScaleY);
                if (!Utility.IsFlagSet((int)this._chromeInfo.NonClientFrameEdges, 1))
                {
                    margin.Right -= SystemParameters.WindowResizeBorderThickness.Left;
                }
                if (!Utility.IsFlagSet((int)this._chromeInfo.NonClientFrameEdges, 4))
                {
                    margin.Right -= SystemParameters.WindowResizeBorderThickness.Right;
                }
                if (!Utility.IsFlagSet((int)this._chromeInfo.NonClientFrameEdges, 2))
                {
                    margin.Bottom -= SystemParameters.WindowResizeBorderThickness.Top;
                }
                if (!Utility.IsFlagSet((int)this._chromeInfo.NonClientFrameEdges, 8))
                {
                    margin.Bottom -= SystemParameters.WindowResizeBorderThickness.Bottom;
                }
                margin.Bottom -= SystemParameters.WindowCaptionHeight;
                Transform renderTransform;
                if (this._window.FlowDirection == FlowDirection.RightToLeft)
                {
                    Thickness thickness = new Thickness(rect2.Left - rect3.Left, rect2.Top - rect3.Top, rect3.Right - rect2.Right, rect3.Bottom - rect2.Bottom);
                    renderTransform = new MatrixTransform(1.0, 0.0, 0.0, 1.0, -(thickness.Left + thickness.Right), 0.0);
                }
                else
                {
                    renderTransform = null;
                }
                frameworkElement.RenderTransform = renderTransform;
            }
            frameworkElement.Margin = margin;
            if (Utility.IsPresentationFrameworkVersionLessThan4 && !this._isFixedUp)
            {
                this._hasUserMovedWindow   = false;
                this._window.StateChanged += this._FixupRestoreBounds;
                this._isFixedUp            = true;
            }
        }
예제 #18
0
        private void _FixupTemplateIssues()
        {
            Assert.IsNotNull(_chromeInfo);
            Assert.IsNotNull(_window);
            if (_window.Template == null)
            {
                return;
            }

            if (VisualTreeHelper.GetChildrenCount(_window) == 0)
            {
                _window.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (_Action)_FixupTemplateIssues);
                return;
            }
            var       templateFixupMargin    = default(Thickness);
            Transform templateFixupTransform = null;

            if (_IsPresentationFrameworkVersionLessThan4)
            {
                var rcWindow         = NativeMethods.GetWindowRect(_hwnd);
                var rcAdjustedClient = _GetAdjustedWindowRect(rcWindow);
                var rcLogicalWindow  = DpiHelper.DeviceRectToLogical(new Rect(rcWindow.Left, rcWindow.Top, rcWindow.Width, rcWindow.Height));
                var rcLogicalClient  =
                    DpiHelper.DeviceRectToLogical(new Rect(rcAdjustedClient.Left, rcAdjustedClient.Top, rcAdjustedClient.Width, rcAdjustedClient.Height));
                var nonClientThickness = new Thickness(rcLogicalWindow.Left - rcLogicalClient.Left, rcLogicalWindow.Top - rcLogicalClient.Top,
                                                       rcLogicalClient.Right - rcLogicalWindow.Right, rcLogicalClient.Bottom - rcLogicalWindow.Bottom);
                templateFixupMargin = new Thickness(0, 0, -(nonClientThickness.Left + nonClientThickness.Right),
                                                    -(nonClientThickness.Top + nonClientThickness.Bottom));

                templateFixupTransform = _window.FlowDirection == FlowDirection.RightToLeft
                    ? new MatrixTransform(1, 0, 0, 1, -(nonClientThickness.Left + nonClientThickness.Right), 0) : null;
            }
            if (_chromeInfo.SacrificialEdge != SacrificialEdge.None)
            {
                if (Utility.IsFlagSet((int)_chromeInfo.SacrificialEdge, (int)SacrificialEdge.Top))
                {
                    templateFixupMargin.Top -= SystemParameters2.Current.WindowResizeBorderThickness.Top;
                }
                if (Utility.IsFlagSet((int)_chromeInfo.SacrificialEdge, (int)SacrificialEdge.Left))
                {
                    templateFixupMargin.Left -= SystemParameters2.Current.WindowResizeBorderThickness.Left;
                }
                if (Utility.IsFlagSet((int)_chromeInfo.SacrificialEdge, (int)SacrificialEdge.Bottom))
                {
                    templateFixupMargin.Bottom -= SystemParameters2.Current.WindowResizeBorderThickness.Bottom;
                }
                if (Utility.IsFlagSet((int)_chromeInfo.SacrificialEdge, (int)SacrificialEdge.Right))
                {
                    templateFixupMargin.Right -= SystemParameters2.Current.WindowResizeBorderThickness.Right;
                }
            }
            var rootElement = (FrameworkElement)VisualTreeHelper.GetChild(_window, 0);

            rootElement.Margin          = templateFixupMargin;
            rootElement.RenderTransform = templateFixupTransform;
            if (_IsPresentationFrameworkVersionLessThan4)
            {
                if (!_isFixedUp)
                {
                    _hasUserMovedWindow   = false;
                    _window.StateChanged += _FixupRestoreBounds;
                    _isFixedUp            = true;
                }
            }
        }