Click to See Complete Forum and Search --> : Get Process Window
nemok
September 9th, 2007, 04:09 PM
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
ovidiucucu
September 9th, 2007, 05:15 PM
One soilution can be the following
Use EnumWindows (http://msdn2.microsoft.com/en-us/library/ms633497.aspx) to enumerate the top-level windows.
In EnumWindowsProc (http://msdn2.microsoft.com/en-us/library/ms633498.aspx) callback function call
GetWindowThreadProcessId (http://msdn2.microsoft.com/en-us/library/ms633522.aspx) to "filter" the window created in the given process.
[ Redirected thread ]
nemok
September 9th, 2007, 10:46 PM
So I have to do it backwards from the window to the process...
ovidiucucu
September 10th, 2007, 03:41 AM
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?
nemok
September 23rd, 2007, 10:03 PM
I am using EnumProcesses() to find a specific window.
I know we can't determine the main window. I thinking of something like GetAllProcessWindows()... :D
TT(n)
October 4th, 2007, 02:23 PM
You should be able to do that in the loop.
VB.NET
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
golanshahar
October 4th, 2007, 03:25 PM
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() (http://msdn2.microsoft.com/en-us/library/ms633506.aspx). ;)
Cheers
ovidiucucu
October 5th, 2007, 03:11 AM
Look also at ::GetGUIThreadInfo() (http://msdn2.microsoft.com/en-us/library/ms633506.aspx). ;)
Does that help more to find out the process main window?
See my previous question (re)mark:
... which can we say "that's the process main window" :) ;) ?
golanshahar
October 5th, 2007, 11:01 AM
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 :D, 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
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.