为控制台应用程序创建GUI! [英] Create a GUI for a console application !?

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

问题描述

您好,我有一个控制台应用程序,它使用命令行参数,我没有源代码,&我想为它创建一个GUI以使其更容易。



我的问题是如何让GUI应用程序调用控制台应用程序&处理其输出结果,将其显示在具有黑色背景和黑色背景的多行编辑控件中。 GUI应用程序中的白色文字!?



请帮帮我



注意:更新。

解决方案

1)第一部分是从UI应用程序调用您的控制台应用程序 - 这很容易。例如,在C ++中,您可以使用正确的命令行参数调用ShellExecute或CreateProcess。我不知道您将使用哪种语言/平台进行用户界面,所以我没有详细说明。



2)第二部分是在UI应用程序中 - 您需要捕获控制台应用程序的输出并将其显示在UI的编辑控件中。有很多方法可以做到这一点,最简单的想法是将控制台应用程序的输出重定向到文本文件,然后读取该文件。要重定向,只需使用>重定向器,例如你应该调用命令行,如ipconfig / all> tmp.txt。显然,这是您的UI应用程序用于调用控制台应用程序的命令行。然后,阅读tmp.txt并分析/显示。


我希望我理解你的问题。

假设您的控制台应用程序的名称是 TestConsole.exe ,它在命令提示符下执行输出ABCDEFGHIJKLM。

现在您需要从具有GUI的应用程序执行此 TestConsole.exe 并在GUI应用程序中获取结果。如果是这种情况,那么在GUI应用程序中编写belwo代码

  char  pchBuffer [ 128 ]; 
FILE * pPipe;
if ((pPipe = _popen( TestConsole rt))!= NULL)
{
while (fgets(pchBuffer, 128 ,pPipe))
{
// pchBuffer将拥有控制台应用程序的输出
// 请在此处写下代码以在编辑控件中显示此内容
/ / 或做任何你想做的事情
}
}


< blockquote>我想你正在寻找这个,



C++/VB - MFC:concurr在GUI编辑框上显示控制台输出。


Hello, I have a console application that works with command line arguments which I don't have its source code, & I want to create a GUI for it to make it easier.

My problem is how to make the GUI application calls the console application & handle its output results to display it in a multi-line edit control with a black background & white text in the GUI application !?

Help me please

NB: Updated.

解决方案

1) The first part is to call your console application from the UI application - this is easy. For example, in C++ you could call ShellExecute, or CreateProcess with correct command line arguments. I don't know what language/platform you will be using for your UI so I do not elaborate much.

2) The second part is inside the UI application - you need to to capture the output from the console application and display it in the edit control of the UI. There are a number of ways to do this, the simplest that comes to mind is to redirect the output of your console app to a text file, and then read that file. To redirect, simply use > redirector, e.g. you should invoke command line such as "ipconfig /all > tmp.txt". Clearly this is the command line that your UI app should be using to invoke the console app. Then, read tmp.txt and analyze/display.


I hope I understand your issue.
Suppose the name of your console application is TestConsole.exeand it gives the output "ABCDEFGHIJKLM" on executing via command prompt.
Now You need to execute this TestConsole.exe from an application that has a GUI and get the result in your GUI application. If this is the situation then write belwo code in your GUI app

char   pchBuffer[128];
FILE   *pPipe;
if( (pPipe = _popen( "TestConsole", "rt" )) != NULL)
{
    while(fgets(pchBuffer, 128, pPipe))
    {
        // pchBuffer will have the output of console application
        // so write here the code to display this in your edit control
        // or do whatever you want
    }
}


I think you are looking for this,

C++/VB - MFC: concurrent display of console output on GUI edit box.


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

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