如何使用 CreateProcess 和最小化主窗口启动控制台应用程序

发布于 2024-10-06 11:32:29 字数 859 浏览 0 评论 0原文

我有一个本机 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛溺水了 2024-10-13 11:32:29

您需要在 STARTUPINFO 结构中指定您希望控制台窗口最初最小化:

ZeroMemory(&si);
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_MINIMIZE;

You need to specify in the STARTUPINFO structure that you want your console window to be initially minimized:

ZeroMemory(&si);
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_MINIMIZE;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文