Reputation: 1428
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.
LATER EDIT I used:
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?
I'm using Visual Studio 2010.
Upvotes: 3
Views: 2842
Reputation: 1082
siStartInfo.dwFlags &= STARTF_USESHOWWINDOW;
siStartInfo.wShowWindow = SW_HIDE;
should do it
Also look at http://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx
Upvotes: 1
Reputation: 665
You must use the STARTUPINFO
structure that you provide as parameter to CreateProcess
.
STARTUPINFO StartInfo= {sizeof(StartInfo)};
StartInfo.dwFlags= STARTF_USESHOWWINDOW;
StartInfo.wShowWindow= SW_HIDE;
Upvotes: 3
Reputation: 7179
The CREATE_NO_WINDOW
flag is used for just this purpose.
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
Upvotes: 9