利用python+win32獲取windows中任務中所有的窗口標題

# #!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2021-06-15 18:06
# @Author : BruceLong
# @FileName: get_win_title.py
# @Email   : [email protected]
# @Software: PyCharm
# @Blog :http://www.cnblogs.com/yunlongaimeng/
from win32gui import *

titles = set()


def foo(hwnd, nouse):
    # 去掉下面這句就所有都輸出了,但是我不需要那麼多
    if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
        titles.add(GetWindowText(hwnd))


EnumWindows(foo, 0)
lt = [t for t in titles if t]
lt.sort()
for t in lt:
    print(t)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章