C ++ Windows CreateChildProcess - 隐藏/不显示子进程的控制台窗口 [英] C++ Windows CreateChildProcess - hide/do not show the child process' console window
问题描述
我需要为我的主进程创建一个子进程作为套接字监听器/服务器,我使用这个调用来实现目标:
I need to create a child process as a socket listener/server for my main process and I use this call to achieve the goal:
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
任何人都可以声明为了子进程的窗口不需要做现身?每次主中央进程创建一个子进程时,都不可能有可见的进程窗口。
Could anyone state what needs to be done in order for the child process' window not to show up? It's undesirable to have a visible process window each time the main, central process creates a child.
稍后编辑我使用了:
HWND hWnd = GetConsoleWindow();
if (hWnd != 0)
{
ShowWindow( hWnd, SW_HIDE);
}
在子进程主函数中,但这不是真的最好的解决方案因为窗口仍然显示了一小部分的一秒钟。如果有几个子进程,每个都有自己的窗口冒泡在屏幕上,它仍然不优雅。是否有任何标志设置为编译器产生一个无控制台输出?
in the child process main function, but this isn't really the best solution as the window still shows up for a fraction of a second. If one has several child processes, each with its own window bubbling onto the screen, it is still not elegant. Are there any flags to set for the compiler to produce a "console-less" output?
我正在使用Visual Studio 2010。
I'm using Visual Studio 2010.
推荐答案
a href =http://msdn.microsoft.com/en-us/library/windows/desktop/ms684863%28v=vs.85%29.aspx> CREATE_NO_WINDOW
标志仅用于此目的。
The CREATE_NO_WINDOW
flag is used for just this purpose.
您可以将其添加到 dwCreationFlags
位掩码因此:
You can add it to the dwCreationFlags
bitmask like so:
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 - 隐藏/不显示子进程的控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!