C++ Windows CreateChildProcess - 隐藏/不显示子进程的控制台窗口

标签 c++ windows process console

我需要为我的主进程创建一个子进程作为套接字监听器/服务器,我使用此调用来实现目标:

bSuccess = CreateProcessA(NULL, 
            cmdLineArgs,   // command line 
            NULL,          // process security attributes 
            NULL,          // primary thread security attributes 
            TRUE,          // handles are inherited 
            HIGH_PRIORITY_CLASS,             // creation flags 
            NULL,          // use parent's environment 
            NULL,          // use parent's current directory 
            &siStartInfo,  // STARTUPINFO pointer 
            &piProcInfo);  // receives PROCESS_INFORMATION 

谁能说明需要做什么才能使子进程的窗口不显示?每次主要的中央进程创建子进程时都有一个可见的进程窗口是不可取的。

后期编辑 我使用了:

HWND hWnd = GetConsoleWindow();
if (hWnd != 0) 
{       
    ShowWindow( hWnd, SW_HIDE);
}

在子进程主函数中,但这并不是真正的最佳解决方案,因为窗口仍会显示几分之一秒。如果一个人有多个子进程,每个子进程都有自己的窗口冒泡到屏幕上,它仍然不够优雅。是否有任何标志可以为编译器设置以产生“无控制台”输出?

我使用的是 Visual Studio 2010。

最佳答案

CREATE_NO_WINDOW标志就是用于此目的。

您可以像这样将它添加到 dwCreationFlags 位掩码中:

bSuccess = CreateProcessA(NULL, 
            cmdLineArgs,   // command line 
            NULL,          // process security attributes 
            NULL,          // primary thread security attributes 
            TRUE,          // handles are inherited 
            HIGH_PRIORITY_CLASS | CREATE_NO_WINDOW,  // creation flags 
            NULL,          // use parent's environment 
            NULL,          // use parent's current directory 
            &siStartInfo,  // STARTUPINFO pointer 
            &piProcInfo);  // receives PROCESS_INFORMATION 

关于C++ Windows CreateChildProcess - 隐藏/不显示子进程的控制台窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13954537/

相关文章:

c++ - Qt C++ 在文件中写入数据,意外输出

c++ - 为什么不能通过索引号将字符串的元素 append 到 C++ 中的新字符串?

java - 如何在Java类中执行cmd命令?

c# 处理参数和缺少输出

java - Android:从 C++ 调用带有 byte[] 参数的 java 方法

c++ - 有没有一种简单的方法可以将 C++ 枚举转换为字符串?

windows - Kinect USB 3.0 经常重连

.net - 如何模拟 .net 应用程序的低内存?

c++ - 谈论套接字时的同步和异步术语

python - 检查进程是否仅使用 Python 内置模块在 Windows 中运行