Window handle (hwnd) from process or thread info

Mark Hammond mhammond at skippinet.com.au
Tue Mar 18 05:39:10 EST 2003


Constant wrote:
> The Win32 CreateProcess(), including the win32process.CreateProcess(),
> function return the following info about the process that it just created:
> 
>     HANDLE hProcess
>     HANDLE hThread
>     DWORD dwProcessId
>     DWORD dwThreadId
> 
> Is it possible to get the window handle (HWND) of the window, that was
> created by this process, from these pieces of information?

Use win32api.EnumWindows() to enumerate all top-level windows, then call 
win32process.GetWindowThreadProcessId() to see if the process ID for the 
hwnd is the window you just created.

Obviously, the process may take some time to create the window, may 
create many windows, or may not create one at all.

Mark.





More information about the Python-list mailing list