How to show Window and command-line prompt?
Is there a way to show a Window and CMD in combination? I would like to use the cmd as a debugging info logger in my Window application.开发者_StackOverflow中文版
There are two approaches.
You can continue to link your application as a windowed application, and use
AllocConsole
to create a console window in which you can output your debugging information. Note that this only opens kernel handles, so you would need to use_open_osfhandle
and_fdopen
to connect stdout/stderr to your console.You can link your application as a console application, not forgetting that it now starts with
_tmain
instead of_tWinMain()
.
Yes this is totally possible. Write a console application and proceed with regular window registration, create a window and listen for events. Note that using the blocking standard input on the same thread as the one with your window message loop should be avoided (window becomes unresponsive as long as the console input operation is not finished).
Note that you can still allocate a console from a windowed application, but I'm not sure if the standard output and standard error are bound to the console I/O buffers.
Whatever console application can manage windows by calling CreateWindow
and performing a message loop like a window app.
And whatever window app (the one entering with WinMain
) can associate a console with AllocConsole
.
They are not so much different, after all! ;-)
If you want to use that for debugging purposes only, in a Visual C++ environment, why don't you use the Windows defined macro TRACE(). It well serves the purpose of debugging. It will write in the output window of Visual Studio. And it is very simple.
精彩评论