Original Post
Hi everyone, I have been trying to figure this out for weeks on how to programmatically open a console window alongside an XNA game. I know you can open a console window by right clicking your project->properties->Application->Output type->"Console Application" but this makes it always appear. I am wondering how to have this same effect but via code. You may be asking why? The answer is simple, I want the Console window for Debugging & scripting purposes when running in debug mode on windows but any other time I just want the game to run.
In C# and DirectX games I use to just use the below code to achieve this, I am wondering if something similar works in XNA (note this opens a window but it is unable to accept input or write output):
Any help or suggestions would be greatly appreciated.
In C# and DirectX games I use to just use the below code to achieve this, I am wondering if something similar works in XNA (note this opens a window but it is unable to accept input or write output):
[DllImport("kernel32.dll")]
public static extern Int32 AllocConsole();
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetConsoleWindow();
public void init() {
AllocConsole();
IntPtr MyConsole = GetConsoleWindow();
SetWindowPos(MyConsole, 0, 0, 0, 0, 0, 0x0001);
Console.WriteLine("*************************************************************");
Console.WriteLine("\t\t\tDEBUG CONSOLE");
Console.WriteLine("*************************************************************");
}
Any help or suggestions would be greatly appreciated.