Browse Source

Respect WindowState when showing window.

Fixed #436.
pull/447/head
Steven Kirk 11 years ago
parent
commit
9ca500aa0c
  1. 3
      src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs
  2. 48
      src/Windows/Perspex.Win32/WindowImpl.cs

3
src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs

@ -622,6 +622,9 @@ namespace Perspex.Win32.Interop
[DllImport("user32.dll")]
public static extern bool IsWindowUnicode(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool KillTimer(IntPtr hWnd, IntPtr uIDEvent);

48
src/Windows/Perspex.Win32/WindowImpl.cs

@ -33,6 +33,7 @@ namespace Perspex.Win32
private bool _isActive;
private bool _decorated = true;
private double _scaling = 1;
private WindowState _showWindowState;
public WindowImpl()
{
@ -145,24 +146,14 @@ namespace Perspex.Win32
set
{
UnmanagedMethods.ShowWindowCommand command;
switch (value)
if (UnmanagedMethods.IsWindowVisible(_hwnd))
{
case WindowState.Minimized:
command = UnmanagedMethods.ShowWindowCommand.Minimize;
break;
case WindowState.Maximized:
command = UnmanagedMethods.ShowWindowCommand.Maximize;
break;
case WindowState.Normal:
command = UnmanagedMethods.ShowWindowCommand.Restore;
break;
default:
throw new ArgumentException("Invalid WindowState.");
ShowWindow(value);
}
else
{
_showWindowState = value;
}
UnmanagedMethods.ShowWindow(_hwnd, command);
}
}
@ -267,7 +258,7 @@ namespace Perspex.Win32
public virtual void Show()
{
UnmanagedMethods.ShowWindow(_hwnd, UnmanagedMethods.ShowWindowCommand.Normal);
ShowWindow(_showWindowState);
}
public void BeginMoveDrag()
@ -640,5 +631,28 @@ namespace Perspex.Win32
UnmanagedMethods.ScreenToClient(_hwnd, ref p);
return new Point(p.X, p.Y);
}
private void ShowWindow(WindowState state)
{
UnmanagedMethods.ShowWindowCommand command;
switch (state)
{
case WindowState.Minimized:
command = UnmanagedMethods.ShowWindowCommand.Minimize;
break;
case WindowState.Maximized:
command = UnmanagedMethods.ShowWindowCommand.Maximize;
break;
case WindowState.Normal:
command = UnmanagedMethods.ShowWindowCommand.Restore;
break;
default:
throw new ArgumentException("Invalid WindowState.");
}
UnmanagedMethods.ShowWindow(_hwnd, command);
}
}
}

Loading…
Cancel
Save