create an independent hidden process
- by Jessica
I'm creating an application with its main window hidden by using the following code:
STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
siStartupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_FORCEOFFFEEDBACK | STARTF_USESTDHANDLES;
siStartupInfo.wShowWindow = SW_HIDE;
if(CreateProcess(MyApplication, "", 0, 0, FALSE, 0, 0, 0, &siStartupInfo, &piProcessInfo) == FALSE)
{
// blah
return 0;
}
Everything works correctly except my main application (the one calling this code) window loses focus when I open the new program.
I tried lowering the priority of the new process but the focus problem is still there.
Is there anyway to avoid this? furthermore, is there any way to create another process without using CreateProcess (or any of the API's that call CreateProcess like ShellExecute)?
My guess is that my app is losing focus because it was given to the new process, even when it's hidden.
To those of you curious out there that will certainly ask the usual "why do you want to do this", my answer is because I have a watchdog process that cannot be a service and it gets started whenever I open my main application. Satisfied?
Thanks for the help. Code will be appreciated.
Jess.