import sys
sys.path.insert(0, ".")
import ctypes
import src.common.win32_window as w

w.attach_to_default_desktop()
u = ctypes.windll.user32
fg = u.GetForegroundWindow()

buf = ctypes.create_unicode_buffer(512)
u.GetWindowTextW(fg, buf, 512)
cls = ctypes.create_unicode_buffer(256)
u.GetClassNameW(fg, cls, 256)
print(f"Foreground HWND: {fg}, Title: '{buf.value}', Class: '{cls.value}'")

def cb(child, lparam):
    t = ctypes.create_unicode_buffer(512)
    u.GetWindowTextW(child, t, 512)
    c = ctypes.create_unicode_buffer(256)
    u.GetClassNameW(child, c, 256)
    if t.value.strip():
        print(f"  Child {child} [{c.value}]: {t.value}")
    return True

WNDENUMPROC = ctypes.WINFUNCTYPE(ctypes.wintypes.BOOL, ctypes.wintypes.HWND, ctypes.wintypes.LPARAM)
u.EnumChildWindows(fg, WNDENUMPROC(cb), 0)
