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