From 2b4e95e64a235bd79af1a1b34c4e062624dadb93 Mon Sep 17 00:00:00 2001 From: DB P Date: Mon, 2 Jun 2025 14:55:46 +0900 Subject: [PATCH] Block window maximize and prevent resizing in WndProc --- Flow.Launcher.Infrastructure/Win32Helper.cs | 7 +++++++ Flow.Launcher/MainWindow.xaml.cs | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 96d8e925b..5d340c6f7 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -163,6 +163,13 @@ namespace Flow.Launcher.Infrastructure SetWindowStyle(hwnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (int)newExStyle); } + public static void BlockWindowMaximize(Window window, HwndSourceHook hook) + { + var handle = GetWindowHandle(window, true); + var hwndSource = HwndSource.FromHwnd(handle); + hwndSource.AddHook(hook); + } + /// /// Restore window display in the Alt+Tab window list. /// diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index f15091e4a..49f180e80 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -490,6 +490,12 @@ namespace Flow.Launcher #region Window WndProc + private const int WM_NCLBUTTONDBLCLK = 0x00A3; + private const int WM_SYSCOMMAND = 0x0112; + private const int SC_MAXIMIZE = 0xF030; + private const int SC_RESTORE = 0xF120; + private const int SC_MINIMIZE = 0xF020; + private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == Win32Helper.WM_ENTERSIZEMOVE) @@ -541,7 +547,20 @@ namespace Flow.Launcher handled = true; } - + if (msg == WM_NCLBUTTONDBLCLK) + { + SizeToContent = SizeToContent.Height; + handled = true; + } + else if (msg == WM_SYSCOMMAND) + { + int command = wParam.ToInt32() & 0xFFF0; + if (command == SC_MAXIMIZE || command == SC_MINIMIZE) + { + SizeToContent = SizeToContent.Height; + handled = true; + } + } return IntPtr.Zero; }