Search code examples
pythonwinapiprocesspywin32

Can several windows be bound to the same process?


I cannot quite understand what does win32gui.EnumWindows. When called like

win32gui.EnumWindows(enumHandler, lParam)

def enumHandler(hwnd, lParam):
    print win32process.GetWindowThreadProcessId(hwnd)

it prints tuples, some of which are the same. For example

...
[4860, 4640]
[4860, 4640]
[4860, 4640]
[4860, 4640]
[4860, 4640]
...

Does it mean that several windows are bound to the same thread id and process id? How is that possible?


Solution

  • Windows are associated with threads. Threads are associated with processes. A thread can create as many top-level windows as it likes. Therefore you can perfectly well have multiple top-level windows associated with the same thread.