您当前的位置: 首页 >  Python
  • 0浏览

    0关注

    516博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

不太灵光的程序员 发布时间:2019-11-06 09:17:22 ,浏览量:0

文章目录
  • python获取窗口句柄

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窗口程序

关注
打赏
1664870321
查看更多评论
立即登录/注册

微信扫码登录

0.0423s