一个Win32控制台应用程序的多个控制台窗口 [英] Multiple console windows from one Win32 console app

查看:158
本文介绍了一个Win32控制台应用程序的多个控制台窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个程序,基于一个空的Win32控制台应用程序在VS2008运行在Win7 64位。该程序是从 main.cpp 完全基于菜单的产卵,它只调用导致基于用户需要的其他接口的外部函数(例如收银员,库存,报告等) ..)。我想做的是为每个接口提供一个新的控制台窗口。


理想情况下,在用户通过其功能进行调用时调用任何其他界面等,将关闭主菜单,包括在必要时重新打开主菜单。



这样做的基础是我下星期开始一个新学期,用C ++深入研究OOP,我想翻译我的文本并完成上限项目进展与主题,以确保我有所有的基础下拍。正如我最喜欢做这个聪明最简单的方法,最好是如果我坚持本书中提出的有限的知识,只提示 STL ,没有什么其他库如 boost



我当然已经在SO和其他地方寻找解决方案。我找到了答案,大多数都落在我的严格要求之外,一些处理从头开始构建控制台窗口。虽然从头开始似乎是最有前途的,它似乎是处理那些没有使用像VS一样的健壮的IDE,我不知道它是否会导致更多的冲突比它的价值,或者如果它甚至可以用于多重性。然而,大多数人给我留下的印象是不可能的。一个例外是将控制台链接到进程。这是我希望在我的未来!



为什么让我这么做是需要提出一个干净的看看每一个事件。起初,我试图用一个基本函数清除屏幕,例如 void clearScreen(int lines); ,但这将总是从底部清除。所以,如果我在下一个界面之前清除屏幕,它仍然在底部。如果我清除它然后接受输入,提示仍然在底部。

I've written a program based on an empty Win32 console app in VS2008 running on Win7 64bit. The program is entirely menu based spawning from a main.cpp which only calls external functions that lead to other interfaces based on the users needs (e.g. cashier, inventory, report, etc...). What I would love to do is provide a new console window for each interface.

Ideally it would close the main menu upon invoking any other interfaces and so on as the user progresses through its functions, including reopening the main menu when necessary.

The basis for doing it this way is that I'm starting a new semester next week diving deeper in OOP with C++ and I wanted to go over my text and complete the capstone project which progresses with the topics to ensure that I have all the basics down pat. As much as I would love to do this the smartest-easiest way, it's best if I stick to the limited knowledge presented in the book which only hints at STL and speaks nothing of additional libraries like boost.

I, of course, have searched on SO and elsewhere looking for the solution. I have found answers, most of them falling outside of my tight requirements, some dealing with building a console window from scratch. While from-scratch seems the most promising, it seemed to be dealing with those not using a robust IDE like VS and I don't know if it will cause more conflict than it's worth, or if it can even be used in multiplicity. The majority, however, left me with the impression it isn't possible. The one exception to this was linking a console to a process. This is what I hope is in my future!

What brought me to this was the need to present a clean look at each turn of events. At first I was fooling around with trying to clear the screen with a basic function like void clearScreen(int lines); but this will always clear from the bottom. So, if I clear the screen before the next interface it's still at the bottom. If I clear it then accept input, the prompt is still at the bottom.

如果它还没有清楚到这一点。我的问题是:

是否可能,在原因之内,产生绑定到进程的多个控制台窗口,或有一个简单的方法,我不知道操纵主控制台窗口的滚动?


即使我需要保持在传统学习的婴儿步骤的范围内,我想听到任何输入,除了切换应用程序类型。



这是一个比任务的要求更多的OCD问题,所以如果努力不值得的好处也没关系。


我很高兴发布任何代码,我只是没有看到它如何将有益于这个问题!


Muchos gracias!

In case it hasn't been clear up to this point. My question is:
Is it possible, within reason, to produce multiple console windows which are tied to processes, or is there an easy way which I do not know to manipulate the scrolling of the main console window?
Even though I "need" to stay within the confines of the baby-step process of traditional learning, I would love to hear any input aside from switching the app type.

This is more of an OCD issue than a requirement of the task, so if the effort isn't worth the benefit that's okay too.
I would be glad to post any code, I just didn't see how it would benefit the question!
Muchos gracias!

推荐答案

虽然我的原始问题可能不清楚,我在寻找一个在控制台窗口中使用的解决方案。理想情况下,该解决方案至少可以在Linux和Windows上运行,因为我为学校写的任何程序都必须在每个程序上编译。这不是一个作业,但显然有利于学习那些在那里可用的东西。

Although it may not have been clear in my original question, I was looking for a solution to be used in a console window. Ideally the solution would have been operable on at least Linux and Windows because any programs I write for school must be compiled on each. This wasn't an assignment but it's obviously advantageous to learn things that are usable there as well.

这是我发现的

。 。。感谢Tim Wei

void clearScreen()
{
    #ifdef _WIN32
        system("cls");
    #else
        system("clear");
    #endif
}

我在找什么。该函数清除屏幕,并将光标置于控制台窗口的顶部,提供一种方式来提供具有变化的数据表的静态头或标题。它还允许简单的基于文本的动画 - 如果你喜欢那种事情。它在我的控制台应用程序在这个学期的外观,感觉和一致性有显着的区别!

This, as simple as it is, was exactly what I was looking for. The function clears the screen and puts the cursor at the top of the console window providing a way to provide static headers or titles with changing data tables. It also allows for simple text based animations - if you like that sort of thing. It made a significant difference in the look, feel and consistency in my console applications this semester!

这篇关于一个Win32控制台应用程序的多个控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆