import ctypes, sys, win32gui
from ctypes import wintypes

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

hwnds = []
def cb(h, _):
    txt_len = user32.GetWindowTextLengthW(h) + 1
    txt_buf = ctypes.create_unicode_buffer(txt_len)
    user32.GetWindowTextW(h, txt_buf, txt_len)
    if "JXHelper" in txt_buf.value and user32.IsWindowVisible(h):
        hwnds.append(h)
    return True

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

main_hwnd = hwnds[0]
print(f"Main HWND: {hex(main_hwnd)}")

children = []
def child_cb(h, _):
    cls_buf = ctypes.create_unicode_buffer(256)
    user32.GetClassNameW(h, cls_buf, 256)
    r = win32gui.GetWindowRect(h)
    mr = win32gui.GetWindowRect(main_hwnd)
    rel = (r[0] - mr[0], r[1] - mr[1], r[2] - r[0], r[3] - r[1])
    children.append((h, cls_buf.value, rel))
    return True

user32.EnumChildWindows(main_hwnd, WNDENUMPROC(child_cb), 0)

CB_GETCOUNT = 0x0146
CB_GETCURSEL = 0x0147
CB_GETLBTEXT = 0x0148
CB_GETLBTEXTLEN = 0x0149

for h, cls, rel in children:
    if "ComboBox" in cls:
        cnt = user32.SendMessageW(h, CB_GETCOUNT, 0, 0)
        cur = user32.SendMessageW(h, CB_GETCURSEL, 0, 0)
        print(f"Combo {hex(h)}: rel={rel}, count={cnt}, cur={cur}")
        if cnt > 0:
            for i in range(cnt):
                tlen = user32.SendMessageW(h, CB_GETLBTEXTLEN, i, 0)
                tbuf = ctypes.create_unicode_buffer(tlen + 1)
                user32.SendMessageW(h, CB_GETLBTEXT, i, ctypes.byref(tbuf))
                print(f"   [{i}]: {tbuf.value}")
