python3 遍历windows下 所有句柄及窗口名称

遍历windows 所有可显示的窗口句柄及窗口名称。


import win32gui
hwnd_title = dict()
def get_all_hwnd(hwnd,mouse):
    if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
        hwnd_title.update({hwnd:win32gui.GetWindowText(hwnd)})
win32gui.EnumWindows(get_all_hwnd, 0)

for h,t in hwnd_title.items():
    if t is not "":
        print(h, t)

结果 :

1576952 mypython [D:\mypython] - ...\test.py [mypython] - PyCharm
6425832 Python 运算符 | 菜鸟教程 - Google Chrome
264212 IT学习讨论组等20个会话
2754364 无标题 - 记事本
3018460 Xshell 5
3673256 Spy++
4264012 计算器
1903766 计算器
984780 Microsoft Edge
1313006 Microsoft Edge
396206 Microsoft Edge

猜你喜欢

转载自blog.csdn.net/gamers/article/details/82423128