Results 1 to 6 of 6

Thread: Obtaining Windows Handle for Child Process

  1. #1
    Join Date
    Jan 2008
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Obtaining Windows Handle for Child Process

    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:

    Qt Code:
    1. hParent = winId();
    2. .
    3. .
    4. process.start( "cmd.exe", args);
    5. SetWindowPos( hParent, HWND_BOTTOM, x, y, cx, cy, SWP_NOSIZE);
    6. hChild = GetForeGroundWindow();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Obtaining Windows Handle for Child Process

    I'm sure you can obtain it through QProcess::pid().

  3. #3
    Join Date
    Jan 2008
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Obtaining Windows Handle for Child Process

    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:

    Qt Code:
    1. Q_PID pid;
    2.  
    3. hChild = pid->hProcess;
    To copy to clipboard, switch view to plain text mode 

    gives a compiler error:

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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Obtaining Windows Handle for Child Process

    It's not a window handle but a process handle.

  5. #5
    Join Date
    Jan 2008
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Obtaining Windows Handle for Child Process

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Obtaining Windows Handle for Child Process

    It doesn't have to contain the handle. There probably is some WinAPI call that asks for window handles of a particular process.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.