import ctypes
from ctypes import wintypes

user32 = ctypes.windll.user32

hdesk = user32.OpenInputDesktop(0, False, 0x01FF)
if hdesk:
    user32.SetThreadDesktop(hdesk)

def get_text(hwnd):
    length = user32.GetWindowTextLengthW(hwnd) + 1
    buf = ctypes.create_unicode_buffer(length)
    user32.GetWindowTextW(hwnd, buf, length)
    return buf.value

def enum_children(hwnd):
    children = []
    def child_cb(h, _):
        cls_buf = ctypes.create_unicode_buffer(256)
        user32.GetClassNameW(h, cls_buf, 256)
        children.append((h, cls_buf.value, get_text(h)))
        return True
    WNDENUMPROC = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)
    user32.EnumChildWindows(hwnd, WNDENUMPROC(child_cb), 0)
    return children

def enum_cb(hwnd, _):
    cls_buf = ctypes.create_unicode_buffer(256)
    user32.GetClassNameW(hwnd, cls_buf, 256)
    if cls_buf.value == '#32770':
        pid = wintypes.DWORD()
        user32.GetWindowThreadProcessId(hwnd, ctypes.byref(pid))
        print(f'Dialog HWND: {hex(hwnd)}, Title: "{get_text(hwnd)}", PID: {pid.value}')
        for ch, ch_cls, ch_txt in enum_children(hwnd):
            print(f'   Child HWND: {hex(ch)}, Class: {ch_cls}, Text: "{ch_txt}"')
    return True

WNDENUMPROC = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)
user32.EnumWindows(WNDENUMPROC(enum_cb), 0)
