如何使用 CreateProcess 和最小化主窗口启动控制台应用程序
我有一个本机 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
所有参数都在 STARTUPINFO 块 0 中。此代码在启动进程时工作正常。但是,我需要能够在窗口最小化的情况下启动 Windows C++ 控制台应用程序。
如果我将 CREATE_NO_WINDOW 添加到进程创建标志,我可以在没有任何窗口的情况下启动进程。这将是不可接受的。
在我的研究中,似乎没有办法强制控制台应用程序以最小化模式打开。这是正确的吗?
是的,我知道我可以在自己的进程中最小化子应用程序窗口,但是,团队中的其他程序员不愿意这样做。
I have a native c++ windows application that is launching two child processes using the following code -
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.
If I add CREATE_NO_WINDOW to the Process Create Flags, I can launch the processes without any windows. This will be unacceptable.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在 STARTUPINFO 结构中指定您希望控制台窗口最初最小化:
You need to specify in the STARTUPINFO structure that you want your console window to be initially minimized: