0

I'm developing a game using C# and XNA 4.0, and my project's startup type is a console application (to help with debugging advanced elements).

My question has 2 parts:

  1. Is it possible to completely hide/disable the console window from within the game code?
  2. If not, is it possible to change the startup type from an external application (a game launcher) ?

I know the obvious solution is to just set my startup type to "Windows Application" for the public releases, and keep it as a console for debugging and developer versions, however I would like users to be able to turn on the console for debug data if they're having problems.

John Saunders
  • 160,644
  • 26
  • 247
  • 397

3 Answers3

0

sounds like an X/Y Problem to me, i would reconsider your requirements here and your approach to the problem, do you really expect users to look at a command prompt if they are having issues.

I would consider writing a debug class that handles all this for you and adding it to you main game loop so that it can draw to screen if required

RoughPlace
  • 1,111
  • 1
  • 13
  • 23
0

What you actually need is a logger like log4net or nlog

You can install it easily via the Nuget visual studio extension.

You then monitor the log file via a viewer like baretail

Regex search and replace on Console.WriteLine()

LukeN
  • 1,698
  • 15
  • 29
0

This stack overflow answer seems to indicate that you can open a console window by making some native calls.

Essentially you can make your app's startup type to be the windows app, then call AllocConsole to register a console to your application, which redirects stdin, stdout and stderr from the process to the console.

I'd still agree with the other answerers, some sort of logging framework would make more sense. If you use something like log4net you could do both for your debugging purposes, include a console appender in the log4net config and allocate a console if you pass a command line arg to your app.

Community
  • 1
  • 1
Matt
  • 2,984
  • 1
  • 24
  • 31