"""List child windows of a given HWND (all descendants).""" import sys import win32gui def walk(hwnd, depth=0, max_depth=4, out=None): out = out if out is not None else [] if depth > max_depth: return out kids = [] def cb(h, _): kids.append(h) return True try: win32gui.EnumChildWindows(hwnd, cb, None) except Exception: pass for h in kids: rect = win32gui.GetWindowRect(h) out.append((depth, h, win32gui.GetClassName(h), win32gui.GetWindowText(h), rect, bool(win32gui.IsWindowVisible(h)))) return out if __name__ == '__main__': hwnd = int(sys.argv[1]) rows = walk(hwnd) for depth, h, cls, title, rect, vis in rows[:80]: print(f"{' '*depth}{h} cls={cls!r} title={title!r} rect={rect} vis={vis}") print("total:", len(rows))