Skip to content

Commit 2b4e95e

Browse files
committed
Block window maximize and prevent resizing in WndProc
1 parent a06cb43 commit 2b4e95e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ public static void HideFromAltTab(Window window)
163163
SetWindowStyle(hwnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (int)newExStyle);
164164
}
165165

166+
public static void BlockWindowMaximize(Window window, HwndSourceHook hook)
167+
{
168+
var handle = GetWindowHandle(window, true);
169+
var hwndSource = HwndSource.FromHwnd(handle);
170+
hwndSource.AddHook(hook);
171+
}
172+
166173
/// <summary>
167174
/// Restore window display in the Alt+Tab window list.
168175
/// </summary>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,12 @@ private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs
490490

491491
#region Window WndProc
492492

493+
private const int WM_NCLBUTTONDBLCLK = 0x00A3;
494+
private const int WM_SYSCOMMAND = 0x0112;
495+
private const int SC_MAXIMIZE = 0xF030;
496+
private const int SC_RESTORE = 0xF120;
497+
private const int SC_MINIMIZE = 0xF020;
498+
493499
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
494500
{
495501
if (msg == Win32Helper.WM_ENTERSIZEMOVE)
@@ -541,7 +547,20 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
541547

542548
handled = true;
543549
}
544-
550+
if (msg == WM_NCLBUTTONDBLCLK)
551+
{
552+
SizeToContent = SizeToContent.Height;
553+
handled = true;
554+
}
555+
else if (msg == WM_SYSCOMMAND)
556+
{
557+
int command = wParam.ToInt32() & 0xFFF0;
558+
if (command == SC_MAXIMIZE || command == SC_MINIMIZE)
559+
{
560+
SizeToContent = SizeToContent.Height;
561+
handled = true;
562+
}
563+
}
545564
return IntPtr.Zero;
546565
}
547566

0 commit comments

Comments
 (0)