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")]