From 2ff13940cc728293fb4b620dc86325c41af9c43d Mon Sep 17 00:00:00 2001 From: Andras Schaffer Date: Sat, 21 Oct 2023 19:51:34 +0200 Subject: [PATCH] MainV2: Fix console window hide in windows11 --- MainV2.cs | 4 ++-- NativeMethods.cs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/MainV2.cs b/MainV2.cs index 301c032a35..107958546a 100644 --- a/MainV2.cs +++ b/MainV2.cs @@ -879,8 +879,8 @@ public MainV2() } else { - int win = NativeMethods.FindWindow("ConsoleWindowClass", null); - NativeMethods.ShowWindow(win, NativeMethods.SW_HIDE); // hide window + NativeMethods.ShowWindow(NativeMethods.GetConsoleWindow(), NativeMethods.SW_HIDE); + } // prevent system from sleeping while mp open diff --git a/NativeMethods.cs b/NativeMethods.cs index 78309ee5e1..a8aa1686a1 100644 --- a/NativeMethods.cs +++ b/NativeMethods.cs @@ -10,7 +10,7 @@ internal static class NativeMethods public static extern int FindWindow(string szClass, string szTitle); [DllImport("user32.dll")] - public static extern int ShowWindow(int Handle, int showState); + public static extern bool ShowWindow(IntPtr Handle, int showState); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] internal static extern IntPtr RegisterDeviceNotification @@ -18,6 +18,10 @@ internal static extern IntPtr RegisterDeviceNotification IntPtr NotificationFilter, Int32 Flags); + + [DllImport("kernel32.dll")] + public static extern IntPtr GetConsoleWindow(); + // Import SetThreadExecutionState Win32 API and necessary flags [DllImport("kernel32.dll")]