A customer had the following question:
I'm using theShellExecutefunction to launch a new process and am passing the handle to my application's main window as thehwndparameter. From the new process, I want to get information from the old process, and to do that, I need the window handle. How can I recover that window handle from the new process?
You can't.
That window handle is used by the ShellExecute
function only to host any user interface operations that occur
as a result of the attempt to execute the program.
For example, it is the owner window used for any error dialogs.
The ShellExecute function does not pass the window
handle to the launched process.
(It couldn't even if it wanted to:
There is nowhere to pass it.
There is no window handle among the parameters to
CreateProcess nor is there a window handle
in the
STARTUPINFO structure.)
If you want to pass this information to the process being launched, you'll have to come up with your own mechanism for transferring this information. For example, you can pass it on the command line, or if you have a lot of information to pass, you can use a shared memory block.