diff --git a/MainForm.cs b/MainForm.cs index 3c3a0c8..6c22fa1 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -187,6 +187,10 @@ private void SnapTop() IntPtr focussedWindow = Native.GetForegroundWindow(); Screen windowScreen = Screen.FromHandle(focussedWindow); + // Windows gets confused if you move a maximised window, interestingly breaking the maximise button. + // To avoid any such issues we restore the window before moving it. + Native.ShowWindow(focussedWindow, Native.SW_RESTORE); + // Get window x border. int windowBorderX = GetWindowXBorder(focussedWindow); @@ -222,6 +226,10 @@ private void SnapBottom() IntPtr focussedWindow = Native.GetForegroundWindow(); Screen windowScreen = Screen.FromHandle(focussedWindow); + // Windows gets confused if you move a maximised window, interestingly breaking the maximise button. + // To avoid any such issues we restore the window before moving it. + Native.ShowWindow(focussedWindow, Native.SW_RESTORE); + // Get window x border. int windowBorderX = GetWindowXBorder(focussedWindow); diff --git a/Native.cs b/Native.cs index c0ca832..b3036fc 100644 --- a/Native.cs +++ b/Native.cs @@ -139,6 +139,9 @@ public override string ToString() public const uint SWP_ASYNCWINDOWPOS = 0x4000; public const uint SWP_NOCOPYBITS = 0x0100; + // Same for SW_* values as above. + public const int SW_RESTORE = 9; + // Same for WM_* values as above. public const int WM_HOTKEY = 0x0312; @@ -168,5 +171,9 @@ public override string ToString() [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32.dll")] public static extern bool ScreenToClient(IntPtr hWnd, ref POINT lpPoint); + + [return: MarshalAs(UnmanagedType.Bool)] + [DllImport("user32.dll")] + public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); } } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index ea7b51d..99a5af5 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -11,7 +11,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Snapper")] -[assembly: AssemblyCopyright("Copyright © Jacob Allen 2020")] +[assembly: AssemblyCopyright("Copyright © Jacob Allen 2020-2021")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -33,5 +33,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.*")] +[assembly: AssemblyVersion("1.4.*")] [assembly: NeutralResourcesLanguage("en-GB")]