I ashed this question on the cpp.builder.nativeapi forum but go no reply so
am trying here.
I am using the following code to start another process ( exe file ). I want
the application that I am starting ( child ) to go into the background and
this application ( parent ) to remain unchanged ( it may itself also be in
the background )
Can someone advise what I need to do to accomplish this. I have searched
Google and the Win SDK but have not found the answer. I still want the new
app to appear on the task bar. I just do not want it to become the
foreground task.
TIA
Peter
// --- snip ----
memset(&sStartUpInfo,0, sizeof(sStartUpInfo)) ;
sStartUpInfo.cb = sizeof(sStartUpInfo) ;
sStartUpInfo.dwFlags = STARTF_USESHOWWINDOW ;
sStartUpInfo.wShowWindow = SW_SHOWDEFAULT ;
nExitCode =CreateProcess(NULL, cParam, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE |
NORMAL_PRIORITY_CLASS,NULL,NULL, &sStartUpInfo, &sProcessInfo) ;
.......
"Peter Rees" <pe...@NOOSPAMMrees.co.nz> wrote in message
news:4134e891$1...@newsgroups.borland.com...
> I am using the following code to start another process ( exe file ). I
want
> the application that I am starting ( child ) to go into the background and
> this application ( parent ) to remain unchanged ( it may itself also be in
> the background )
> // --- snip ----
>
> memset(&sStartUpInfo,0, sizeof(sStartUpInfo)) ;
> sStartUpInfo.cb = sizeof(sStartUpInfo) ;
> sStartUpInfo.dwFlags = STARTF_USESHOWWINDOW ;
> sStartUpInfo.wShowWindow = SW_SHOWDEFAULT ;
> nExitCode =CreateProcess(NULL, cParam, NULL, NULL, FALSE,
> CREATE_NEW_CONSOLE |
> NORMAL_PRIORITY_CLASS,NULL,NULL, &sStartUpInfo, &sProcessInfo) ;
> .......
You are nearly there -- instead of SW_SHOWDEFAULT though, try SW_SHOWNA or
SW_SHOWNOACTIVATE
Damien
Damien,
Thanks. I just tried that but the child still comes to the front. Drat :-)
Regards
Peter
var
H: hWnd;
function GetWin(Handle: HWND; LParam: Longint): Bool; stdcall;
begin
if Getparent(Handle) = 0 then
begin
H := Handle;
SetWindowPos(H, HWND_BOTTOM, 0,0,0,0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_SHOWWINDOW);
end;
end;
var
Startupinfo: TStartupinfo;
Processinfo: TProcessInformation;
begin
FillChar(StartupInfo, SizeOf(StartupInfo), 0);
with StartupInfo do
begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := SW_HIDE;
end;
CreateProcess('c:\windows\notepad.exe', nil, nil, nil,
False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
while (H = 0) {and limit to 10 secs} do
begin
Application.ProcessMessages;
EnumThreadWindows(Processinfo.dwThreadid, @Getwin, 0);
end;
end;
"Peter Rees" <pe...@NOOSPAMMrees.co.nz> schreef in bericht news:4134e891$1...@newsgroups.borland.com...
"Peter Rees" <pe...@NOOSPAMMrees.co.nz> wrote in message
news:4134fe83$1...@newsgroups.borland.com...
> Thanks. I just tried that but the child still comes to the front. Drat :-)
Fudge; well reading the docs a little closer it would appear that the value
specified will only have an affect if the child uses ShowWindow(hWnd,
SW_DEFAULT) -- if it specifies SW_NORMAL or any other flag when displaying
it's window then the value from CreateProcess is ignored.
David seems to have hit upon a possible solution though; sorry I couldn't be
of more help.
Damien
Thanks for your help. It works. I modified you idea slightly to use
WaitForInputIdle( sProcessInfo.hProcess, 15000 ) ; // Wait up to 15
seconds for process to start
so no need for while() loop
Also used SetForegroundWindow( hWndThis ) to restore foreground window.
Regards
Peter