C++ Windows CreateChildProcess - 隐藏/不显示子进程的控制台窗口
C++ Windows CreateChildProcess - hide/do not show the child process' console window
我需要为我的主过程创建一个子进程作为套接字侦听器/服务器,我使用此调用来实现目标:
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 Studio2010。
CREATE_NO_WINDOW
标志仅用于此目的。
您可以将其添加到dwCreationFlags
bitmask中:
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
您必须使用作为CreateProcess
参数提供的STARTUPINFO
结构。
STARTUPINFO StartInfo= {sizeof(StartInfo)};
StartInfo.dwFlags= STARTF_USESHOWWINDOW;
StartInfo.wShowWindow= SW_HIDE;
siStartInfo.dwFlags &= STARTF_USESHOWWINDOW;
siStartInfo.wShowWindow = SW_HIDE;
应该做
还请查看http://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v = vs.85).aspx
相关文章:
- 终止 QProcess 不会终止子进程
- 什么时候最好在子进程中使用 CPU 或 I/O 密集型代码 [ C++ ]
- 子进程更新共享 mmap 内存,但父进程没有更改
- 使用 waitpid 时等待子进程终止
- 使用重定向标准处理子进程中的 kbhit
- 由 JOB 中的进程启动的子进程是否可以将 JOB 属性设置为脱离作业?
- 是否可以将子进程的 stdout 重定向到父进程中的另一个文件?
- kill() 总是返回 0(成功),即使在子进程已经结束之后?
- 父进程和子进程之间的 POSIX 信号量
- 检测到由于操作系统内存不足而导致子进程终止
- 使用system()创建独立的子进程
- 从stdin读取时子进程挂起(fork/dup2竞争条件)
- 在 Bash 脚本中处理来自子进程的信号
- Qt C++ - 如何成功将数据传递给子进程?
- C++ 窗口本地系统模拟在子进程中失败
- 将类型化数组写入子进程 stdin 无法正常工作
- 将 nodejs 脚本作为子进程执行(而不是从其他脚本执行)
- 使用信号检测子进程何时终止的最佳方法是什么?
- 等待等待失效的子进程
- C++ Windows CreateChildProcess - 隐藏/不显示子进程的控制台窗口