如何不显示从Win32 GUI程序控制台窗口中执行的孩子控制台程序? [英] How to execute child console programs without showing the console window from the Win32 GUI program?

查看:280
本文介绍了如何不显示从Win32 GUI程序控制台窗口中执行的孩子控制台程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我已经搜查SO答案,并没有发现明确的解决这个问题。)

(I've searched SO answers and found no clear solution to this problem.)

我工作的一个MFC GUI程序。该程序运行各种儿童节目,包括控制台程序和Shell命令脚本(.CMD)。

I'm working on a MFC GUI program. This program runs various child programs including console program and shell command script(.cmd).

最初,它显示在一个GUI窗口和一个控制台窗口(与 AllocConsole 创建),因为有来自子进程输出许多控制台。但许多用户抱怨控制台窗口,所以我们决定隐藏控制台窗口。

Initially it displayed one GUI window and one console window (created with AllocConsole) because there are many console output from the child processes. But many users complained about the console window so we decided to hide the console window.

首先试图象下面这样:

if (AllocConsole())
{
    ::ShowWindow(::GetConsoleWindow(), SW_HIDE);
}

好吧,没有控制台窗口,但也有在控制台创建时可见闪烁。
我试过子进程创建几个的CreateProcess 选项干脆控制台窗口prevent的表现,但在很短的失败,我认为这几乎是不可能的。

Okay, no console window but there are visible flicker at the console creation time. I've tried several CreateProcess options for child process creation to prevent showing of console window altogether but failed at short and I think it is practically impossible.

这不是什么大不了的事。我们可以在启动时忽略临时窗口闪烁。

It is not a big deal. We can ignore temporary window flicker at the startup.

这是真的不可能完全隐藏子控制台窗口?

But is it really impossible to hide child console window completely?

推荐答案

设置了STARTUPINFO喜欢本作的CreateProcess的呼叫:

Setup the STARTUPINFO like this for the CreateProcess call:

    STARTUPINFO si = { 0 };
    si.cb = sizeof(si);
    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
    si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
    si.hStdOutput =  GetStdHandle(STD_OUTPUT_HANDLE);
    si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
    si.wShowWindow = SW_HIDE;

这篇关于如何不显示从Win32 GUI程序控制台窗口中执行的孩子控制台程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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