>Without knowing its window title.
>To my understanding if you can't get a Hwnd you can't determine if an app is finished or not. I hope to be mistaken of course :)
>If this is true how could I get a Hwnd to an app I launch with either CreateProcess or ShellExecute (preferably ShellExecute).
>What I basically want to do is :
>
CreateProcess() can identify termination of an app without an hWnd by waiting of the Process Handle to become signalled. This is what API_APPRUN does.
ShellExecute() provides no mechanism to determine whether an app terminates. You have to do a FindWindow() and wait for it to go away to determine termination.
There is a variant of ShellExecute() called ShellExecuteEx() that hands back a processid, which can be used to get a process handle. Unfortunately, if the ShellExecuteEx() initiates a session using DDE, no ProcessID is returned, so no process handle can be retrieved. and you're back to FindWindow(), which means you're sunk.
You have to explicitly use CreateProcess() and wait on the Process Handle to signal to detect termination. With Windows, it's possible to finish editing an object in an MDI app, leave the app running but shut the document, and never terminate, so you're screwed again.
I covered someone else's attempt to use Wscript.Shell to launch a document, which relies on ShellExecuteEx(), which results in an OLE error if another session of the app is open, and an indefinite wait state if the document is closed by Word is left running. He claimed that this is not the case, I can demonstrate the failure easily enough.
>Launch the app
>Wait for it to finish
>Return
>
>I tried :
>CreateProcess
>WaitForSingleObject
>
Any time an MDI app is involved, you're basically sunk. You might experiement with watching for the thread handle rather than the process handle to terminate, but I'm not certain that MDI WIndows run as independent threads in a single process. Repeated using of FindWindow() is not a solution, because the caption of the MDI window is not fixed.
>However if say already there are 2 instances of Word, launching Word with this just returns immediately. Also GetExitCodeProcess shows only one instance as STILL_ACTIVE.