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

teo*_*ron 2 c++ windows console process

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

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 
Run Code Online (Sandbox Code Playgroud)

任何人都可以说明需要做什么才能让子进程的窗口不显示?每次主要的中央进程创建子进程时,都不希望有一个可见的进程窗口.

编辑的后期编辑:

HWND hWnd = GetConsoleWindow();
if (hWnd != 0) 
{       
    ShowWindow( hWnd, SW_HIDE);
}
Run Code Online (Sandbox Code Playgroud)

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

我正在使用Visual Studio 2010.

Sea*_*ine 8

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 
Run Code Online (Sandbox Code Playgroud)