[Qt-interest] QProcess & windo handle

Joerg Bornemann joerg.bornemann at nokia.com
Wed Aug 3 18:09:22 CEST 2011


On 01/08/2011 17:25, ext Folami Nguyen wrote:

> I use QProcess with start method to start application.
> I want to get window handle of launched application, I use EnumWindows
> in slot which is connected with started() signal of QProcess.
> However, I cannot find windows with has process id is same with process
> id which I accquise from QProcess.

Sounds like you are comparing the window handles to the process id...
Here's some sample code:

---snip---
void onProcessStarted()
{
     QProcess *process = qobject_cast<QProcess*>(sender());
     EnumWindows(myEnumWnd, process->pid()->dwProcessId);
}

BOOL CALLBACK myEnumWnd(HWND hwnd, LPARAM lParam)
{
     DWORD dwProcessID;
     GetWindowThreadProcessId(hwnd, &dwProcessID);
     if (lParam == dwProcessID) {
         // We have found a top level window of the
         // process we've started.
         // Now do something with it.
     }
     return TRUE;
}
---snap---


BR,

Jörg



More information about the Qt-interest-old mailing list