Console Window

  • Thread starter Thread starter Jason Callas
  • Start date Start date
J

Jason Callas

I am trying to figure out how to create a console window but cannot figure
out how to do this. I know it can be done since the C# and VB console
template projects do this but I see no code on how this is done.

The only thing I can think of is that there is hidden code to spawn cmd.exe?
Then they somehow direct console.read and console.write calls to the spawned
process.

Any thoughts (and some sample code) would be greatly appreciated.

- Jason
 
Jason,
I am trying to figure out how to create a console window but cannot figure
out how to do this. I know it can be done since the C# and VB console
template projects do this but I see no code on how this is done.

Windows creates the console window, if needed, when you run a console
application. There's no code needed in the application itself to do
this.



Mattias
 
Hi, Jason

you might want to check
ms-help://MS.NETFrameworkSDKv1.1/cpguidenf/html/cpconbuildingconsoleapplicat
ions.htm in Framework Help, or look for Console class.
Alternatively you can use Win32 API, like GetConsoleWindow() to attach
system console.
Platform SDK has also wealth of information on what is possible.

What exactly you want to achieve?

If you want just to open console window - compile application as console
application.

HTH
Alex
 
I am aware that you can just create a console application but that does not
work for my purposes.

I am writing a windows service that COULD be run as a standalone application
by passing a command-line argument. In that case (while in the IDE) I would
want a console window to be opened to handle input and output.

I'm guessing I could always just change the output type of the project to
Console while developing and change it back to Windows when I want to
release it.

- Jason
 
Jason Callas said:
I am aware that you can just create a console application but that does not
work for my purposes.

I am writing a windows service that COULD be run as a standalone application
by passing a command-line argument. In that case (while in the IDE) I would
want a console window to be opened to handle input and output.

I'm guessing I could always just change the output type of the project to
Console while developing and change it back to Windows when I want to
release it.

If you want to create a console optionally, you can use WinConsole:
http://www.codeproject.com/csharp/winconsole.asp

I believe there are a number of libraries like this available, so you
might want to shop around.
 
Back
Top