CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2003
    Location
    Bacau, Romania
    Posts
    474

    Get Process Window

    Hello,

    I have a process handle. How can I get a HWND to it's main window?
    I couldn't find any function in MSDN that does this.

    Thanks
    B.A. (NKProds)

    Here is what I do: http://www.nkprods.com
    I couldn't have done it without your help. Thanks.

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,237

    Re: Get Process Window

    One soilution can be the following


    [ Redirected thread ]
    Last edited by ovidiucucu; September 9th, 2007 at 04:29 PM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Nov 2003
    Location
    Bacau, Romania
    Posts
    474

    Re: Get Process Window

    So I have to do it backwards from the window to the process...
    B.A. (NKProds)

    Here is what I do: http://www.nkprods.com
    I couldn't have done it without your help. Thanks.

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,237

    Re: Get Process Window

    Well, I think, there is not a kind of "GetProcessMainWindow" function because in a process can be created zero, one, or many (top-level) windows.
    So... which can we say "that's the process main window" ?

    BTW. How did you get the process handle?
    Last edited by ovidiucucu; October 5th, 2007 at 02:05 AM. Reason: Added a question mark
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Nov 2003
    Location
    Bacau, Romania
    Posts
    474

    Re: Get Process Window

    I am using EnumProcesses() to find a specific window.
    I know we can't determine the main window. I thinking of something like GetAllProcessWindows()...
    B.A. (NKProds)

    Here is what I do: http://www.nkprods.com
    I couldn't have done it without your help. Thanks.

  6. #6
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Get Process Window

    You should be able to do that in the loop.

    VB.NET
    Code:
    For Each p as Process In Process.GetProcesses
    
       If p.Handle.ToInt32 = YourPHandle AndAlso p.MainWindowHandle.ToInt32 <> 0  Then
          MessageBox.Show(p.MainWindowHandle.ToInt32.ToString)
       End If
    
    Next
    Last edited by TT(n); October 4th, 2007 at 01:33 PM.

  7. #7
    Join Date
    May 2005
    Posts
    4,954

    Re: Get Process Window

    Quote Originally Posted by nemok
    Hello,

    I have a process handle. How can I get a HWND to it's main window?
    I couldn't find any function in MSDN that does this.

    Thanks
    Look also at ::GetGUIThreadInfo().

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  8. #8
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,237

    Re: Get Process Window

    Quote Originally Posted by golanshahar
    Look also at ::GetGUIThreadInfo().
    Does that help more to find out the process main window?
    See my previous question (re)mark:
    Quote Originally Posted by me
    ... which can we say "that's the process main window" ?
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  9. #9
    Join Date
    May 2005
    Posts
    4,954

    Re: Get Process Window

    Quote Originally Posted by ovidiucucu
    Does that help more to find out the process main window?
    See my previous question (re)mark:
    Your comment is correct we cant, but that API can be an alternative for using ::EnumWindows(), you can get the active/focus window without enum the windows... then ::GetAncestor() can be used on the focus/active window... but no one can guarantee if it will lead to the Main Process window , UNLESS Op want to track specific process and not random one, so one look in Spy++ can help him know the windows structure of that specific process.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured