-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide console on startup (windows only)
- Loading branch information
1 parent
0eb08af
commit 714b723
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace NxEditor.Core.Extensions; | ||
|
||
public enum WindowMode : int { Hidden = 0, Visible = 5 } | ||
|
||
public static partial class ConsoleExtension | ||
{ | ||
private static readonly IntPtr _handle = GetConsoleWindow(); | ||
private static WindowMode _current = WindowMode.Visible; | ||
|
||
[LibraryImport("kernel32.dll")] | ||
private static partial IntPtr GetConsoleWindow(); | ||
|
||
[LibraryImport("user32.dll")] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
private static partial bool ShowWindow(IntPtr window_handle, int cmd_show_mode); | ||
|
||
public static void SetWindowMode(WindowMode mode) | ||
{ | ||
_current = mode; | ||
ShowWindow(_handle, (int)mode); | ||
} | ||
|
||
public static void SwapWindowMode() | ||
{ | ||
_current = _current == WindowMode.Hidden | ||
? WindowMode.Visible : WindowMode.Hidden; | ||
ShowWindow(_handle, (int)_current); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters