This Python code shows how to get the list of hwnds from a given pid on Windows.
We use win32gui to enumerate all windows, get their pid to check and then append the hwnd to the list.
We use win32gui to enumerate all windows, get their pid to check and then append the hwnd to the list.
1 2 3 4 5 6 7 8 9 10 11 12 13 | def get_hwnds_for_pid (pid): def callback (hwnd, hwnds): _, found_pid = win32process.GetWindowThreadProcessId (hwnd) if found_pid == pid: hwnds.append (hwnd) return True hwnds = [] win32gui.EnumWindows (callback, hwnds) return hwnds hwnds = get_hwnds_for_pid(3196) print hwnds |
Ingen kommentarer:
Send en kommentar
Bemærk! Kun medlemmer af denne blog kan sende kommentarer.