Skip to main content

ConsoleWindow

A class in Root.Township, WindowsConsole.

Opens a native Windows console window for the game process and sends Console output to it. WindowsServerConsole creates one on its console thread.

Constructors​

MemberWhat it is
ConsoleWindow()Creates a ConsoleWindow with default values.

Fields​

MemberWhat it is
bool IsOpenTrue until the console is shut down or closed; the console thread loops while it's true.
2 private and internal fields
MemberWhat it is
private TextWriter oldOutputThe Console.Out writer from before the redirect, restored on shutdown.
private const int STD_OUTPUT_HANDLEWin32 standard output handle ID (-11).

Methods​

MemberWhat it is
void Initialize()Creates the console, registers the close handler and points Console output at it.
static bool SetConsoleCtrlHandler(ConsoleWindow.HandlerRoutine Handler, bool Add)Win32 call that registers a handler for Ctrl+C and close events.
void SetTitle(string strName)Sets the console window's title.
void Shutdown()Restores the old output, frees the console and marks it closed.
6 private and internal methods
MemberWhat it is
private static bool AllocConsole()Win32 call that creates a console window for the process.
private static bool AttachConsole(uint dwProcessId)Win32 call to attach to another process's console. Not called here.
private bool ConsoleCtrlCheck(ConsoleWindow.CtrlType ctrlType)On close, logoff or shutdown of the console, marks it closed and quits the game with an expected shutdown reason.
private static bool FreeConsole()Win32 call that detaches the process from its console.
private static IntPtr GetStdHandle(int nStdHandle)Win32 call that gets a standard handle (here, standard output).
private static bool SetConsoleTitle(string lpConsoleTitle)Win32 call that sets the console's title.

Used in​

Members of other types that take, return or hold a ConsoleWindow: