python操作windows窗口獲取窗口句柄

python獲取窗口句柄

在Windows下獲取窗口句柄時操作系統版本軟件版本對獲取有影響,就會出現在本地調試正常的程序,交付使用的時候報錯。

查看windows所有可顯示的窗口句柄及窗口名稱。

# -*- coding: utf-8 -*-
"""
File Name  windows_gui
Created on 2019-11-06

@author: jj

"""
import win32gui

hwnd_title = {}

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 :
        print (h, t.decode("gbk"))
if __name__ == '__main__':
    pass

結果 :
(263618L, u’\u5fae\u4fe1’)
(66630L, u’\u5c0f\u706b\u7bad\u901a\u7528\u52a0\u901f’)
(131362L, u’Program Manager’)
(132782L, u’python\u4e2d\u7684\u89e3\u7801\u4e0e\u7f16\u7801 - zhang_cherry\u7684\u535a\u5ba2 - CSDN\u535a\u5ba2 - Google Chrome’)
(67384L, u’\u57ce\u5e02 - \u4e00\u4e09’)
(131572L, u’\u4efb\u52a1\u7ba1\u7406\u5668’)
(329592L, u’work [F:\work] - …\yanchi_auto\windows_gui.py [work] - PyCharm’)
(329492L, u’lot_irrigated_litong_v3 [F:\jfzx_svn\001litongqu3P\03jieguan\03Development\lot_irrigated_litong_v3] - …\bus_prediction\tasks_apscheduler.py [lot_irrigated_litong_v3] - PyCharm’)
(133012L, u’archive_record_gate_report @lot_canal_hongsipu (aliyun) - \u8868 - Navicat Premium’)
(131690L, u’TIM’)

python操作Windows窗口程序

微信搜一搜關注博主領取更多學習諮詢在這裏插入圖片描述

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