import ctypes, sys
from ctypes import wintypes

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

pids = [35076, 38488]
hwnds = []
def cb(h, _):
    pid = wintypes.DWORD()
    user32.GetWindowThreadProcessId(h, ctypes.byref(pid))
    if pid.value in pids:
        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, pid.value, cls_buf.value, txt_buf.value))
    return True

WNDENUMPROC = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)
user32.EnumWindows(WNDENUMPROC(cb), 0)
for h, pid, cls, txt in hwnds:
    print(f"PID {pid} HWND {hex(h)} Class: {cls} Title: {txt}")
