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)); }
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); }
public static Rect DeviceRectToLogical(Rect deviceRectangle) { Point point = DpiHelper.DevicePixelsToLogical(new Point(deviceRectangle.Left, deviceRectangle.Top)); Point point2 = DpiHelper.DevicePixelsToLogical(new Point(deviceRectangle.Right, deviceRectangle.Bottom)); return(new Rect(point, point2)); }
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); }
private void _InitializeWindowNonClientFrameThickness() { Size logical = DpiHelper.DeviceSizeToLogical(new Size((double)Standard.NativeMethods.GetSystemMetrics(SM.CXFRAME), (double)Standard.NativeMethods.GetSystemMetrics(SM.CYFRAME))); int systemMetrics = Standard.NativeMethods.GetSystemMetrics(SM.CYCAPTION); Point point = DpiHelper.DevicePixelsToLogical(new Point(0, (double)systemMetrics)); double y = point.Y; this.WindowNonClientFrameThickness = new Thickness(logical.Width, logical.Height + y, logical.Width, logical.Height); }
private void _InitializeWindowNonClientFrameThickness() { var frameSize = new Size(NativeMethods.GetSystemMetrics(SM.CXSIZEFRAME), NativeMethods.GetSystemMetrics(SM.CYSIZEFRAME)); var frameSizeInDips = DpiHelper.DeviceSizeToLogical(frameSize); var captionHeight = NativeMethods.GetSystemMetrics(SM.CYCAPTION); var captionHeightInDips = DpiHelper.DevicePixelsToLogical(new Point(0, captionHeight)).Y; WindowNonClientFrameThickness = new Thickness(frameSizeInDips.Width, frameSizeInDips.Height + captionHeightInDips, frameSizeInDips.Width, frameSizeInDips.Height); }
private void _InitializeWindowNonClientFrameThickness() { Size deviceSize = new Size((double)NativeMethods.GetSystemMetrics(SM.CXFRAME), (double)NativeMethods.GetSystemMetrics(SM.CYFRAME)); Size size = DpiHelper.DeviceSizeToLogical(deviceSize); int systemMetrics = NativeMethods.GetSystemMetrics(SM.CYCAPTION); double y = DpiHelper.DevicePixelsToLogical(new Point(0.0, (double)systemMetrics)).Y; this.WindowNonClientFrameThickness = new Thickness(size.Width, size.Height + y, size.Width, size.Height); }
private void _InitializeWindowNonClientFrameThickness() { Size frameSize = new Size( NativeMethods.GetSystemMetrics(SM.CXSIZEFRAME), NativeMethods.GetSystemMetrics(SM.CYSIZEFRAME)); Size frameSizeInDips = DpiHelper.DeviceSizeToLogical(frameSize, SystemParameters2.DpiX / 96.0, SystemParameters2.Dpi / 96.0); int captionHeight = NativeMethods.GetSystemMetrics(SM.CYCAPTION); double captionHeightInDips = DpiHelper.DevicePixelsToLogical(new Point(0, captionHeight), SystemParameters2.DpiX / 96.0, SystemParameters2.Dpi / 96.0).Y; WindowNonClientFrameThickness = new Thickness(frameSizeInDips.Width, frameSizeInDips.Height + captionHeightInDips, frameSizeInDips.Width, frameSizeInDips.Height); }
private void _FixupRestoreBounds(object sender, EventArgs e) { if ((this._window.WindowState == WindowState.Maximized || this._window.WindowState == WindowState.Minimized) && this._hasUserMovedWindow) { this._hasUserMovedWindow = false; WINDOWPLACEMENT windowPlacement = NativeMethods.GetWindowPlacement(this._hwnd); RECT rect = this._GetAdjustedWindowRect(new RECT { Bottom = 100, Right = 100 }); Point point = DpiHelper.DevicePixelsToLogical(new Point((double)(windowPlacement.rcNormalPosition.Left - rect.Left), (double)(windowPlacement.rcNormalPosition.Top - rect.Top))); this._window.Top = point.Y; this._window.Left = point.X; } }
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 void _FixupRestoreBounds(object sender, EventArgs e) { if ((_window.WindowState == WindowState.Maximized || _window.WindowState == WindowState.Minimized) && _hasUserMovedWindow) { _hasUserMovedWindow = false; var windowPlacement = NativeMethods.GetWindowPlacement(_hwnd); var rcWindow = new RECT { Bottom = 100, Right = 100 }; var rect = _GetAdjustedWindowRect(rcWindow); var point = DpiHelper.DevicePixelsToLogical(new Point(windowPlacement.rcNormalPosition.Left - rect.Left, windowPlacement.rcNormalPosition.Top - rect.Top)); _window.Top = point.Y; _window.Left = point.X; } }
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 void _FixupRestoreBounds(object sender, EventArgs e) { Assert.IsTrue(_IsPresentationFrameworkVersionLessThan4); if (_window.WindowState == WindowState.Maximized || _window.WindowState == WindowState.Minimized) { if (_hasUserMovedWindow) { _hasUserMovedWindow = false; var wp = NativeMethods.GetWindowPlacement(_hwnd); var adjustedDeviceRc = _GetAdjustedWindowRect(new RECT { Bottom = 100, Right = 100 }); var adjustedTopLeft = DpiHelper.DevicePixelsToLogical(new Point(wp.rcNormalPosition.Left - adjustedDeviceRc.Left, wp.rcNormalPosition.Top - adjustedDeviceRc.Top)); _window.Top = adjustedTopLeft.Y; _window.Left = adjustedTopLeft.X; } } }
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)); }
private void _InitializeCaptionHeight() { Point ptCaption = new Point(0, NativeMethods.GetSystemMetrics(SM.CYCAPTION)); WindowCaptionHeight = DpiHelper.DevicePixelsToLogical(ptCaption).Y; }
public static Size DeviceSizeToLogical(Size deviceSize) { Point point = DpiHelper.DevicePixelsToLogical(new Point(deviceSize.Width, deviceSize.Height)); return(new Size(point.X, point.Y)); }
private void _InitializeCaptionHeight() { Point point = new Point(0, (double)Standard.NativeMethods.GetSystemMetrics(SM.CYCAPTION)); this.WindowCaptionHeight = DpiHelper.DevicePixelsToLogical(point).Y; }
private void _InitializeCaptionHeight() { Point ptCaption = new Point(0, NativeMethods.GetSystemMetrics(SM.CYCAPTION)); this.WindowCaptionHeight = DpiHelper.DevicePixelsToLogical(ptCaption, SystemParameters2.DpiX / 96.0, SystemParameters2.Dpi / 96.0).Y; }