Browse Source

refactored to seperate method.

pull/805/head
Dan Walmsley 10 years ago
parent
commit
4c4342e2dd
  1. 60
      src/Windows/Avalonia.Win32/WindowImpl.cs

60
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -678,44 +678,24 @@ namespace Avalonia.Win32
{ {
UnmanagedMethods.ShowWindowCommand command; UnmanagedMethods.ShowWindowCommand command;
Action afterShow = null; bool maximizeFillsDesktop = false; // otherwise we cover entire screen.
switch (state) switch (state)
{ {
case WindowState.Minimized: case WindowState.Minimized:
command = UnmanagedMethods.ShowWindowCommand.Minimize; command = ShowWindowCommand.Minimize;
break; break;
case WindowState.Maximized: case WindowState.Maximized:
command = UnmanagedMethods.ShowWindowCommand.Maximize; command = ShowWindowCommand.Maximize;
if (!_decorated && !_ignoreTaskBarWhenMaximized) if (!_decorated && !_ignoreTaskBarWhenMaximized)
{ {
IntPtr monitor = MonitorFromWindow(_hwnd, MONITOR.MONITOR_DEFAULTTONEAREST); maximizeFillsDesktop = true;
if (monitor != IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
if (UnmanagedMethods.GetMonitorInfo(monitor, monitorInfo))
{
RECT rcMonitorArea = monitorInfo.rcMonitor;
var x = monitorInfo.rcWork.left;
var y = monitorInfo.rcWork.top;
var cx = Math.Abs(monitorInfo.rcWork.right - x);
var cy = Math.Abs(monitorInfo.rcWork.bottom - y);
afterShow = () =>
{
UnmanagedMethods.SetWindowPos(_hwnd, new IntPtr(-2), x, y, cx, cy, SetWindowPosFlags.SWP_SHOWWINDOW);
};
}
}
} }
break; break;
case WindowState.Normal: case WindowState.Normal:
command = UnmanagedMethods.ShowWindowCommand.Restore; command = ShowWindowCommand.Restore;
break; break;
default: default:
@ -724,12 +704,34 @@ namespace Avalonia.Win32
UnmanagedMethods.ShowWindow(_hwnd, command); UnmanagedMethods.ShowWindow(_hwnd, command);
if (afterShow != null) if(maximizeFillsDesktop)
{ {
afterShow(); MaximizeWithoutCoveringTaskbar();
} }
SetFocus(_hwnd);
}
private void MaximizeWithoutCoveringTaskbar()
{
IntPtr monitor = MonitorFromWindow(_hwnd, MONITOR.MONITOR_DEFAULTTONEAREST);
UnmanagedMethods.SetFocus(_hwnd); if (monitor != IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
if (GetMonitorInfo(monitor, monitorInfo))
{
RECT rcMonitorArea = monitorInfo.rcMonitor;
var x = monitorInfo.rcWork.left;
var y = monitorInfo.rcWork.top;
var cx = Math.Abs(monitorInfo.rcWork.right - x);
var cy = Math.Abs(monitorInfo.rcWork.bottom - y);
SetWindowPos(_hwnd, new IntPtr(-2), x, y, cx, cy, SetWindowPosFlags.SWP_SHOWWINDOW);
}
}
} }
public void SetIcon(IWindowIconImpl icon) public void SetIcon(IWindowIconImpl icon)

Loading…
Cancel
Save