Created
February 22, 2023 17:36
-
-
Save netalkGB/e00de56dbbfd19aa59e193faad928ca8 to your computer and use it in GitHub Desktop.
Windowsの開いてるウインドウたちのタイトルを取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ctypes | |
| user32 = ctypes.windll.user32 | |
| def get_titles(): | |
| titles = [] | |
| def foreach_window(hwnd, lparam): | |
| length = user32.GetWindowTextLengthW(hwnd) | |
| buf = ctypes.create_unicode_buffer(length + 1) | |
| user32.GetWindowTextW(hwnd, buf, length + 1) | |
| titles.append(buf.value) | |
| user32.EnumWindows(ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))(foreach_window), 0) | |
| return titles | |
| print([title for title in get_titles() if title.find("TMIDI Player") >= 0][0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment