| 175 | """Enumerate all visible windows with title.""" |
| 176 | windows = [] |
| 177 | def cb(hwnd, _): |
| 178 | if user32.IsWindowVisible(hwnd): |
| 179 | length = user32.GetWindowTextLengthW(hwnd) |
| 180 | if length > 0: |
| 181 | buf = ctypes.create_unicode_buffer(length + 1) |
| 182 | user32.GetWindowTextW(hwnd, buf, length + 1) |
| 183 | pid = ctypes.c_uint32() |
| 184 | user32.GetWindowThreadProcessId(hwnd, ctypes.byref(pid)) |
| 185 | windows.append({'hwnd': str(hwnd), 'pid': pid.value, 'title': buf.value}) |
| 186 | return True |
| 187 | user32.EnumWindows(WNDENUMPROC(cb), 0) |
| 188 | return windows |
| 189 | |