单个应用程序的多个控制台 C++
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20847474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple consoles for a single application C++
提问by Tom C
Is it possible to create two console windows (one being the main) and the secondary being a pop-up like a message box in Windows Forms?
是否可以创建两个控制台窗口(一个是主窗口),第二个是像 Windows 窗体中的消息框一样的弹出窗口?
I only want the secondary console window to hold IDs (that will be hard coded into the application) So the user does not have to keep returning to the main menu to check available IDs
我只希望辅助控制台窗口保存 ID(这将被硬编码到应用程序中)所以用户不必一直返回主菜单来检查可用的 ID
If so how would you go about it?
如果是这样,你会怎么做?
Many Thanks
非常感谢
回答by herohuyongtao
Yes, you can do it.
是的,你可以做到。
The solution is actually very simple - our process can start a new helper
child-process, so the helper process will display whatever our process sends it. We can easily implement such a solution with pipes: for each new console
(that I'll call logger), we'll open a pipe, and execute a Console-Helper
application - the role of this application is very simple, it will print everything sent through the pipe. Check out this article Multiple consoles for a single applicationfor details (contains the source code).
解决方案实际上非常简单——我们的进程可以启动一个新的helper
子进程,因此辅助进程将显示我们的进程发送的任何内容。我们可以很容易地用管道实现这样的解决方案:对于每个新的console
(我称之为 logger),我们将打开一个管道,并执行一个Console-Helper
应用程序——这个应用程序的作用很简单,它将打印通过管道。查看这篇文章单个应用程序的多个控制台了解详细信息(包含源代码)。
In the code, it implement a console class CConsoleLogger
, then you can create multiple console windows like:
在代码中,它实现了一个控制台类CConsoleLogger
,然后您可以创建多个控制台窗口,例如:
CConsoleLogger another_console;
another_console.Create("This is the first console");
another_console.printf("WOW !!! COOLL !!! another console ???");
And you will get something like:
你会得到类似的东西:
回答by Jon Trauntvein
Take a look at http://msdn.microsoft.com/en-us/library/windows/desktop/ms682528(v=vs.85).aspxfor instructions for creating a console window.
有关创建控制台窗口的说明,请查看http://msdn.microsoft.com/en-us/library/windows/desktop/ms682528(v=vs.85).aspx。