private void HandleMaximize() { bool flag; bool flag1; this.borderThicknessChangeNotifier.ValueChanged -= new EventHandler(this.BorderThicknessChangeNotifierOnValueChanged); this.topMostChangeNotifier.ValueChanged -= new EventHandler(this.TopMostChangeNotifierOnValueChanged); MetroWindow associatedObject = base.AssociatedObject as MetroWindow; bool enableDWMDropShadow = this.EnableDWMDropShadow; if (associatedObject != null) { if (associatedObject.GlowBrush != null) { flag1 = false; } else { flag1 = (associatedObject.EnableDWMDropShadow ? true : this.EnableDWMDropShadow); } enableDWMDropShadow = flag1; } if (base.AssociatedObject.WindowState != WindowState.Maximized) { this.windowChrome.ResizeBorderThickness = SystemParameters.WindowResizeBorderThickness; if (!enableDWMDropShadow) { base.AssociatedObject.BorderThickness = this.savedBorderThickness.GetValueOrDefault(new Thickness(0)); } } else { this.windowChrome.ResizeBorderThickness = new Thickness(0); base.AssociatedObject.BorderThickness = new Thickness(0); flag = (associatedObject == null ? false : associatedObject.IgnoreTaskbarOnMaximize); bool flag2 = flag; if (flag && this.handle != IntPtr.Zero) { IntPtr intPtr = UnsafeNativeMethods.MonitorFromWindow(this.handle, 2); if (intPtr != IntPtr.Zero) { MahApps.Metro.Native.MONITORINFO mONITORINFO = new MahApps.Metro.Native.MONITORINFO(); UnsafeNativeMethods.GetMonitorInfoW(intPtr, mONITORINFO); int num = (flag2 ? mONITORINFO.rcMonitor.left : mONITORINFO.rcWork.left); int num1 = (flag2 ? mONITORINFO.rcMonitor.top : mONITORINFO.rcWork.top); int num2 = (flag2 ? Math.Abs(mONITORINFO.rcMonitor.right - num) : Math.Abs(mONITORINFO.rcWork.right - num)); int num3 = (flag2 ? Math.Abs(mONITORINFO.rcMonitor.bottom - num1) : Math.Abs(mONITORINFO.rcWork.bottom - num1)); UnsafeNativeMethods.SetWindowPos(this.handle, new IntPtr(-2), num, num1, num2, num3, 64); } } } base.AssociatedObject.Topmost = false; base.AssociatedObject.Topmost = (base.AssociatedObject.WindowState == WindowState.Minimized ? true : this.savedTopMost); this.borderThicknessChangeNotifier.ValueChanged += new EventHandler(this.BorderThicknessChangeNotifierOnValueChanged); this.topMostChangeNotifier.ValueChanged += new EventHandler(this.TopMostChangeNotifierOnValueChanged); }
private void HandleMaximize() { borderThicknessChangeNotifier.ValueChanged -= BorderThicknessChangeNotifierOnValueChanged; topMostChangeNotifier.ValueChanged -= TopMostChangeNotifierOnValueChanged; var metroWindow = AssociatedObject as MetroWindow; var enableDWMDropShadow = EnableDWMDropShadow; if (metroWindow != null) { enableDWMDropShadow = metroWindow.GlowBrush == null && (metroWindow.EnableDWMDropShadow || EnableDWMDropShadow); } if (AssociatedObject.WindowState == WindowState.Maximized) { // remove resize border and window border, so we can move the window from top monitor position // note (punker76): check this, maybe we doesn't need this anymore windowChrome.ResizeBorderThickness = new Thickness(0); AssociatedObject.BorderThickness = new Thickness(0); var ignoreTaskBar = metroWindow != null && metroWindow.IgnoreTaskbarOnMaximize; if (ignoreTaskBar && handle != IntPtr.Zero) { // WindowChrome handles the size false if the main monitor is lesser the monitor where the window is maximized // so set the window pos/size twice IntPtr monitor = UnsafeNativeMethods.MonitorFromWindow(handle, Constants.MONITOR_DEFAULTTONEAREST); if (monitor != IntPtr.Zero) { var monitorInfo = new MahApps.Metro.Native.MONITORINFO(); UnsafeNativeMethods.GetMonitorInfo(monitor, monitorInfo); //ignoreTaskBar = metroWindow.IgnoreTaskbarOnMaximize || metroWindow.UseNoneWindowStyle; var x = ignoreTaskBar ? monitorInfo.rcMonitor.left : monitorInfo.rcWork.left; var y = ignoreTaskBar ? monitorInfo.rcMonitor.top : monitorInfo.rcWork.top; var cx = ignoreTaskBar ? Math.Abs(monitorInfo.rcMonitor.right - x) : Math.Abs(monitorInfo.rcWork.right - x); var cy = ignoreTaskBar ? Math.Abs(monitorInfo.rcMonitor.bottom - y) : Math.Abs(monitorInfo.rcWork.bottom - y); UnsafeNativeMethods.SetWindowPos(handle, new IntPtr(-2), x, y, cx, cy, 0x0040); } } } else { // note (punker76): check this, maybe we doesn't need this anymore windowChrome.ResizeBorderThickness = SystemParameters2.Current.WindowResizeBorderThickness; if (!enableDWMDropShadow) { AssociatedObject.BorderThickness = savedBorderThickness.GetValueOrDefault(new Thickness(0)); } } // fix nasty TopMost bug // - set TopMost="True" // - start mahapps demo // - TopMost works // - maximize window and back to normal // - TopMost is gone // // Problem with minimize animation when window is maximized #1528 // 1. Activate another application (such as Google Chrome). // 2. Run the demo and maximize it. // 3. Minimize the demo by clicking on the taskbar button. // Note that the minimize animation in this case does actually run, but somehow the other // application (Google Chrome in this example) is instantly switched to being the top window, // and so blocking the animation view. AssociatedObject.Topmost = false; AssociatedObject.Topmost = AssociatedObject.WindowState == WindowState.Minimized || savedTopMost; borderThicknessChangeNotifier.ValueChanged += BorderThicknessChangeNotifierOnValueChanged; topMostChangeNotifier.ValueChanged += TopMostChangeNotifierOnValueChanged; }
internal static extern IntPtr MonitorFromPoint(POINT pt, MONITORINFO.MonitorOptions dwFlags);
internal static extern bool GetMonitorInfo([In] IntPtr hMonitor, [Out] MONITORINFO lpmi);