I'm going out on a limb here, but I think you generally want to hide the console application window.
In this case, you can achieve this through some P / Invoking.
I lied. The source code I posted just disables the "X" button in the tray. Sorry for the confusion ...
WinForms.ShowWindow(consoleWindow, NativeConstants.SW_HIDE)
[DllImport("user32.dll")]
public static extern Boolean ShowWindow(IntPtr hWnd, Int32 show);
And the P / Invoke instructions here:
[DllImport("user32.dll")]
public static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
Original code
private static IntPtr hWndConsole = IntPtr.Zero;
private static IntPtr hWndMenu = IntPtr.Zero;
public static void Main(string[] args)
{
hWndConsole = WinForms.GetConsoleWindow();
if (hWndConsole != IntPtr.Zero)
{
hWndMenu = WinForms.GetSystemMenu(hWndConsole, false);
if (hWndMenu != IntPtr.Zero)
{
WinForms.EnableMenuItem(hWndMenu, NativeConstants.SC_CLOSE, (uint)(NativeConstants.MF_GRAYED));
}
}
}
source
share