import ctypes
user32 = ctypes.windll.user32
kernel32 = ctypes.windll.kernel32

hwinsta = user32.OpenWindowStationW("WinSta0", False, 0x10000000)
if hwinsta: user32.SetProcessWindowStation(hwinsta)
hdesk = user32.OpenDesktopW("Default", 0, False, 0x10000000)
if hdesk: user32.SetThreadDesktop(hdesk)

hwnd = user32.FindWindowW("POEWindowClass", None)
print('Find POEWindowClass:', hex(hwnd) if hwnd else None)
hwnd2 = user32.FindWindowW(None, "Path of Exile 2")
print('Find Path of Exile 2:', hex(hwnd2) if hwnd2 else None)

def cb(h, extra):
    length = user32.GetWindowTextLengthW(h)
    buf = ctypes.create_unicode_buffer(length + 1)
    user32.GetWindowTextW(h, buf, length + 1)
    cbuf = ctypes.create_unicode_buffer(256)
    user32.GetClassNameW(h, cbuf, 256)
    if "Exile" in buf.value or "POE" in cbuf.value or "PathOfExile" in buf.value:
        print(f'Found HWND {hex(h)}: Title="{buf.value}", Class="{cbuf.value}"')
    return True

WNDENUMPROC = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.c_int, ctypes.c_int)
user32.EnumWindows(WNDENUMPROC(cb), 0)
