>>Hi I havce an app which uses shellexecute to open files, but I really want to get the handle of these apps once shellexecute has opened them, but I do not want to have to look at every window.
>>
>>Is there a API which I can pass the PID of the application and get the window handle ?
>>
>>Thanks in advance
>>
>Steven,
>
>No you can't. The value returned by ShellExecute() is not a true instance handle to the application under Win32. It is provided for backward compatibility with Win16. The only thing it's good for is to determine whether or not the function call was successful.
>
>ShellExecuteEx() does have some useful information, but since it requires embedded pointers to strings in the structure it receives, it is difficult to use within VFP. If this is of interest, I'd suggest you download either (or both) Christof Lange's STRUCT file or Ed Rauh's CLSHEAP. Both can be found in the files section (under Win32 and Other APIs). One more note about ShellExecuteEx()...its information does not include the window handle if that's what you're after. Further, assuming that the window is not hidden and is currently active after the ShellExecute() call, GetActiveWindow() will return this value.
ShellExecuteEx() does not guarentee that you will receive back a valid process ID since no new process is necessarily spawned if the OLE linkage for the file action is based on DDE and an existing instance of the application is running; the implementation is non-trivial. If a process handle is returned, you can terminate the process with it via TerminateProcess() or PostThreadMessage() once you get the ThreadID for the thread servicing the document, using a WM_CLOSE or WM_QUIT, but for a number of reasons you may not be able to accurately determine if processing the document has completed, especially if DDE linkage to an MDI app is involved. Extensive review of the MSDN Library documentation on ShellExecuteEx() is required to rely on using it properly.