import win32gui
import win32process
import ctypes
from ctypes import wintypes
import sys

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

# AutoVLBS PID 38488
hwnds = []
def enum_cb(h, _):
    _, pid = win32process.GetWindowThreadProcessId(h)
    if pid == 38488 and user32.IsWindowVisible(h):
        txt_len = user32.GetWindowTextLengthW(h) + 1
        txt_buf = ctypes.create_unicode_buffer(txt_len)
        user32.GetWindowTextW(h, txt_buf, txt_len)
        cls_buf = ctypes.create_unicode_buffer(256)
        user32.GetClassNameW(h, cls_buf, 256)
        hwnds.append((h, cls_buf.value, txt_buf.value))
    return True

user32.EnumWindows(ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)(enum_cb), 0)
print("AutoVLBS Visible Windows:")
for h, cls, txt in hwnds:
    print(f"HWND: {hex(h)}, Class: {cls}, Text: '{txt}'")

# Main window of AutoVLBS
if hwnds:
    main_vlbs = hwnds[0][0]
    controls = []
    def child_cb(h, _):
        txt_len = user32.GetWindowTextLengthW(h) + 1
        txt_buf = ctypes.create_unicode_buffer(txt_len)
        user32.GetWindowTextW(h, txt_buf, txt_len)
        cls_buf = ctypes.create_unicode_buffer(256)
        user32.GetClassNameW(h, cls_buf, 256)
        controls.append((h, cls_buf.value, txt_buf.value))
        return True
    user32.EnumChildWindows(main_vlbs, ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)(child_cb), 0)
    print(f"\nTotal child controls in AutoVLBS: {len(controls)}")
    for h, cls, txt in controls:
        if txt.strip():
            print(f"  {hex(h)} [{cls}]: '{txt.strip()}'")
