windows 如何使用最小化主窗口的 CreateProcess 启动控制台应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4380575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to launch console application using CreateProcess with Minimized main window
提问by photo_tom
I have a native c++ windows application that is launching two child processes using the following code -
我有一个本机 c++ windows 应用程序,它使用以下代码启动两个子进程 -
if (!CreateProcess(NULL, // No module name (use command line)
cmdLine, // szCmdline, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
false, // Set handle inheritance to FALSE
CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS // Process Create Flags
NULL, // Use parent's environment block
NULL, // workingDir, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi) // Pointer to PROCESS_INFORMATION structure
with all parameters in STARTUPINFO block 0. This code works fine in launching the processes. However, I need to be able to launch the windows c++ console applications with their windows minimized.
使用 STARTUPINFO 块 0 中的所有参数。此代码在启动进程时工作正常。但是,我需要能够在最小化窗口的情况下启动 windows c++ 控制台应用程序。
If I add CREATE_NO_WINDOW to the Process Create Flags, I can launch the processes without any windows. This will be unacceptable.
如果我将 CREATE_NO_WINDOW 添加到进程创建标志,我可以在没有任何窗口的情况下启动进程。这将是不可接受的。
In my research, there does not appear to be a way force a console application to open in a minimized mode. Is this correct?
在我的研究中,似乎没有办法强制控制台应用程序以最小化模式打开。这样对吗?
Yes, I know that I could minimize the child application windows from within their own process, however, the other programmers on the team prefer not to do this.
是的,我知道我可以从他们自己的进程中最小化子应用程序窗口,但是,团队中的其他程序员不愿意这样做。
回答by Frédéric Hamidi
You need to specify in the STARTUPINFOstructure that you want your console window to be initially minimized:
您需要在STARTUPINFO结构中指定您希望控制台窗口最初最小化:
ZeroMemory(&si);
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_MINIMIZE;