简体   繁体   中英

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.

There are two approaches.

  1. 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.

  2. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM