Python 3.10 Windows获取当前所有应用句柄,使用 win32gui
import win32gui
def get_hwnd_dic(hwnd, hwnd_title):
if (win32gui.IsWindow(hwnd)
and win32gui.IsWindowEnabled(hwnd)
and win32gui.IsWindowVisible(hwnd)
and win32gui.GetWindowText(hwnd)):
hwnd_title[f"{hwnd}"] = win32gui.GetWindowText(hwnd)
def get_hwnd():
"""
:return: {hwnd:title}
"""
hwnd_title = {}
win32gui.EnumWindows(get_hwnd_dic, hwnd_title)
return hwnd_title
hwndJson = get_hwnd()
print(hwndJson)