import ctypes, win32process
from ctypes import wintypes
user32 = ctypes.windll.user32
hdesk = user32.OpenInputDesktop(0, False, 0x01FF)
if hdesk: user32.SetThreadDesktop(hdesk)

def cb(h, _):
    _, pid = win32process.GetWindowThreadProcessId(h)
    if pid == 16112:
        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)
        print(f'HWND: {hex(h)}, Class: {cls_buf.value}, Title: "{txt_buf.value}", Visible: {user32.IsWindowVisible(h)}')
    return True

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