在Windows窗体中嵌入一个DOS控制台 [英] Embedding a DOS console in a windows form

查看:689
本文介绍了在Windows窗体中嵌入一个DOS控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在Windows窗体或用户控件嵌入一个DOS控制台C#2.0?

Is it possible to embed a DOS console in a Windows Form or User Control in C# 2.0?

我们有我的Windows应用程序必须与交互的传统DOS的产品,它已经要求传统产品的实例应该在Windows应用程序中运行。

We have a legacy DOS product that my Windows app has to interact with, and it's been requested that an instance of the legacy product should run within the Windows application.

目前,我使用的user32.dll中找到的DOS产品运行中,然后最小化最大化窗口的窗口,并键入字符到窗口。这不是一个很好的解决这个问题,因为这意味着我的应用程序存储在应用程序设置窗口名称,并要求用户使用互动功能之前返回到DOS应用程序的正确的页面。

At the moment, I'm using the user32.dll to locate the window that the DOS product is running in, minimising then maximising the window, and typing characters into the window. This isn't a very good solution to the problem, as it means my application has to store the window name in application settings, and requires that the user returns to the correct page of the DOS app before using the interaction function.

编辑:一些详细信息。

的继承应用程序需要对用户可见,但不是在一个单独的窗口。

The legacy app needs to be visible to the user, but not in a separate window.

我试过TimothyP的答案,它工作得很好,但有可能实现相同的功能,但在视觉上嵌入在Windows窗体或用户控件,而不是在自己的窗口弹出的DOS窗口?在一个ShowDialog的()方法preferably使得用户不能使用该应用诡计它们在传统模式交互,可以这么说。

I've tried TimothyP's answer and it works very well, but is it possible to achieve the same functionality, but with the DOS window visually embedded in a windows form or user control instead of popping up in it's own window? Preferably in a ShowDialog() way so that the user cannot interact with the app wile they are in 'Legacy Mode', so to speak.

推荐答案

这是可能的重定向使用Process类的控制台/ DOS应用程序的标准输入/输出。它看起来是这样的:

It's possible to redirect the standard input/output of console/dos applications using the Process class. It might look something like this:

var processStartInfo = new ProcessStartInfo("someoldapp.exe", "-p someparameters");

processStartInfo.UseShellExecute = false;
processStartInfo.ErrorDialog = false;

processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.CreateNoWindow = true;

Process process = new Process();
process.StartInfo = processStartInfo;
bool processStarted = process.Start();

StreamWriter inputWriter = process.StandardInput;
StreamReader outputReader = process.StandardOutput;
StreamReader errorReader = process.StandardError;
process.WaitForExit();

您现在可以使用流与应用程序交互。
通过processStartInfo.CreateNoWindow设置为true原来的应用程序将被隐藏。

You can now use the streams to interact with the application. By setting processStartInfo.CreateNoWindow to true the original application will be hidden.

我希望这有助于。

这篇关于在Windows窗体中嵌入一个DOS控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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