PDA

View Full Version : Obtaining Windows Handle for Child Process



GTBuilder
18th March 2008, 19:29
Is there any way to get the windows handle for a child process besides waiting for the process to start and using something like the following to push the parent down to ensure the child is on top:



hParent = winId();
.
.
process.start( "cmd.exe", args);
SetWindowPos( hParent, HWND_BOTTOM, x, y, cx, cy, SWP_NOSIZE);
hChild = GetForeGroundWindow();

wysota
18th March 2008, 19:39
I'm sure you can obtain it through QProcess::pid().

GTBuilder
19th March 2008, 10:42
Wysota, thanks for pointing me in the right direction. Unfortunately I'm now stuck with how to extract the handle from the PROCESS_INFORMATION structure that Q_PID points to.

The following code:



Q_PID pid;

hChild = pid->hProcess;


gives a compiler error:

invalid conversion from 'void*' to 'HWND_*' :confused:

wysota
19th March 2008, 10:44
It's not a window handle but a process handle.

GTBuilder
19th March 2008, 11:32
OK, now I'm back to square one. Q_PID points to PROCESS_INFORMATION which doesn't contain the HWND I'm looking for. I was hoping there was a better way then using
GetForegroundWindow(). Or am I missing something fundamental here. I've only just started to digging into WinAPI.

wysota
19th March 2008, 21:54
It doesn't have to contain the handle. There probably is some WinAPI call that asks for window handles of a particular process.