C#多控制台窗口 [英] C# Multi Console Window

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

问题描述

大家好,

如果您阅读了我的最后一个问题,那么我正在做一个游戏,但是我还需要知道如何使多控制台窗口彼此交互.就像我要做某事一样,在主窗口中它将保留我刚刚所做的工作的数据,但随后另一个将在屏幕上写一些东西.我想要这个的原因是因为制作了清单,我想要在其中包含游戏和所有数据的主窗口,但是我希望另一个窗口显示我的统计信息和清单.

hey guys,

if you read my last question, i am making a game, but i also need to know how to make multi console windows interact with each other. like if i were to do something, in the main window it would keep the data of what i just did, but then another would write something to the screen. the reason i want this is because of making my inventory, i want to have the main window with the game and all the data stored in there, but i want the other window to show my stats and my inventory.

推荐答案

不支持多个控制台.根据控制台API上的MSDN文档,一个进程只能附加一个控制台.
Multiple consoles are not supported. According to the MSDN doc''s on the Console API, a process can only have a single console attached.


答案是是"和是".否,因为Windows不允许一个进程具有多个控制台,是的,因为您可以通过一些不太复杂的技巧获得相同的结果.本文介绍了如何使用c ++进行操作:针对单个应用程序的多个控制台 [ ^ ],但是有一些方法可以从.net使用它或将其转录为c#.
The answer is no and yes. No, because windows does not allow a process to have multiple consoles, and yes, because you can achieve the same result with some not so complicated tricks. This article is describing how to do it in c++: Multiple consoles for a single application[^], but there are ways to use it from .net or transcribe it to c#.


您好,

该应用程序只能有一个是正确的.但是谁告诉您可以为每个控制台做其他应用程序呢?
使用函数CreateProcess并指定控制台应用程序路径(您甚至可以使用Windows应用程序并调用AllocConsole API).为了与您的应用通信,您可以使用SetStdHandle为子进程指定stdin和/或stdout并通过它进行通信.您可以使用多种方法进行进程间通信.例如NamedPipes:您可以在一个应用程序中通过共享的命名事件进行管道传输和发信号,并在另一个应用程序中读取.其他方法是使用共享内存:请参阅CreateFileMapping API.加上使用线程句柄,您可以检查子进程是否仍然存在.连同它一起,您可以使用PostThreadMessage,或广播通过RegisterWindowMessage注册的消息.因此,只需对该部分进行研究,然后决定哪种方法对您的情况更好.

戴夫(Dave):我经常看到的同一件事-问题是如何做",而不是可能与否".同样的建议-不要提供仅与个人经验有关的不支持",不可能"的解决方案.我想知道有人否决了这个问题,因为那是什么,从那时开始,如果这是必需的,而您不知道如何实现呢? -不好-如果您不知道解决方案,将问题留给比您聪明的人,不要表明您无法提供正确的答案.

问候,
Maxim.
Hello,

The application can have only one concole that''s true. But who told that you can do additional application for each console?
Use function CreateProcess and specify your console application path (you may even use the windows application and call AllocConsole API). For comunication with your app you can specify stdin and/or stdout for your child process by using SetStdHandle and comunicate via it. There are a lot of methods for interprocess comunications you can use one of them. For example NamedPipes: you can trite to pipe and signal via shared named event in one application and read in another. Other way is to usage of shared memory: see CreateFileMapping API. Plus using the thread handle you can check if child process alive or not. Along with it you can use PostThreadMessage, or broadcast messages registered via RegisterWindowMessage. So just research in that part and decide what is better for your case.

For Dave: Same thing as I have seen mostly - the question is "how to", but not the "possible or not". And Same suggestion - Do not provide the solution with the "not supported" "not possible" - that is related only to personal experience. I wonder that someone downvote the question, since what is that, from that point if this is required and you don''t know how to implement that? - That''s not good - if you don''t know the solution leave the question to someone smarter than you and do not show that you can''t provide proper answer.

Regards,
Maxim.


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

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