Skip to content

Commit 69d9f3f

Browse files
committed
Fix window focus after minimize when not debugging
1 parent b4768e4 commit 69d9f3f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ManagedShell.WindowsTasks/ApplicationWindow.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public void BringToFront()
588588
else
589589
{
590590
// If the window is maximized, use ShowMaximize so that it doesn't un-maximize
591-
if (GetWindowShowStyle(Handle) != NativeMethods.WindowShowStyle.ShowMaximized ||
591+
if (GetWindowShowStyle(Handle) != NativeMethods.WindowShowStyle.ShowMaximized ||
592592
!NativeMethods.ShowWindow(Handle, NativeMethods.WindowShowStyle.ShowMaximized))
593593
{
594594
NativeMethods.ShowWindow(Handle, NativeMethods.WindowShowStyle.Show);
@@ -603,8 +603,9 @@ public void Minimize()
603603
{
604604
if ((WindowStyles & (int)NativeMethods.WindowStyles.WS_MINIMIZEBOX) != 0)
605605
{
606-
IntPtr retval = IntPtr.Zero;
607-
NativeMethods.SendMessageTimeout(Handle, (int)NativeMethods.WM.SYSCOMMAND, NativeMethods.SC_MINIMIZE, 0, 2, 200, ref retval);
606+
NativeMethods.GetWindowThreadProcessId(Handle, out uint procId);
607+
NativeMethods.AllowSetForegroundWindow(procId);
608+
NativeMethods.PostMessage(Handle, (int)NativeMethods.WM.SYSCOMMAND, (IntPtr)NativeMethods.SC_MINIMIZE, IntPtr.Zero);
608609
}
609610
}
610611

0 commit comments

Comments
 (0)