简体   繁体   English

如何显示窗口和命令行提示符?

[英]How to show Window and command-line prompt?

Is there a way to show a Window and CMD in combination? 有没有办法同时显示Window和CMD? I would like to use the cmd as a debugging info logger in my Window application. 我想在Windows应用程序中将cmd用作调试信息记录器。

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. 您可以继续将您的应用程序链接为窗口应用程序,并使用AllocConsole创建一个控制台窗口,您可以在其中输出调试信息。 Note that this only opens kernel handles, so you would need to use _open_osfhandle and _fdopen to connect stdout/stderr to your console. 请注意,这只会打开内核句柄,因此您需要使用_open_osfhandle_fdopen将stdout / stderr连接到控制台。

  2. You can link your application as a console application, not forgetting that it now starts with _tmain instead of _tWinMain() . 您可以将应用程序链接为控制台应用程序,不要忘记它现在以_tmain而不是_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. 请注意,您仍然可以从窗口化的应用程序分配控制台 ,但是我不确定标准输出和标准错误是否绑定到控制台I / O缓冲区。

Whatever console application can manage windows by calling CreateWindow and performing a message loop like a window app. 任何控制台应用程序都可以通过调用CreateWindow并执行类似于窗口应用程序的消息循环来管理窗口。

And whatever window app (the one entering with WinMain ) can associate a console with AllocConsole . 而且,任何窗口应用程序(使用WinMain输入的窗口应用程序)都可以将控制台与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(). 如果只想将其用于调试目的,则在Visual C ++环境中,为什么不使用Windows定义的宏TRACE()。 It well serves the purpose of debugging. 它很好地用于调试的目的。 It will write in the output window of Visual Studio. 它将写在Visual Studio的输出窗口中。 And it is very simple. 这很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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