import ctypes, sys
from ctypes import wintypes
import win32gui, psutil

sys.stdout.reconfigure(encoding='utf-8')
user32 = ctypes.windll.user32
hdesk = user32.OpenInputDesktop(0, False, 0x01FF)
if hdesk: user32.SetThreadDesktop(hdesk)

pids = [p.pid for p in psutil.process_iter(['pid', 'name']) if 'AutoVLBS' in (p.info['name'] or '')]
target_pid = pids[0]
main_hwnd = 0
def cb(h, _):
    global main_hwnd
    pid = wintypes.DWORD()
    user32.GetWindowThreadProcessId(h, ctypes.byref(pid))
    if pid.value == target_pid and user32.IsWindowVisible(h):
        main_hwnd = h
    return True

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

controls = []
def child_cb(ch, _):
    txt_len = user32.GetWindowTextLengthW(ch) + 1
    buf = ctypes.create_unicode_buffer(txt_len)
    user32.GetWindowTextW(ch, buf, txt_len)
    cls_buf = ctypes.create_unicode_buffer(256)
    user32.GetClassNameW(ch, cls_buf, 256)
    controls.append((ch, cls_buf.value, buf.value))
    return True

user32.EnumChildWindows(main_hwnd, WNDENUMPROC(child_cb), 0)
print(f'Main HWND: {hex(main_hwnd)}, Total controls: {len(controls)}')
for h, cls, txt in controls:
    if txt:
        print(f'{hex(h)} [{cls}]: "{txt}"')
