create an independent hidden process
Posted
by Jessica
on Stack Overflow
See other posts from Stack Overflow
or by Jessica
Published on 2009-11-30T14:59:37Z
Indexed on
2010/03/20
19:51 UTC
Read the original article
Hit count: 289
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.
© Stack Overflow or respective owner