pythonenumapi_python 枚举窗体 EnumWindows | 学步园

这篇博客介绍了如何使用Python的win32gui模块遍历Windows系统中的所有窗口,并查找特定类名或标题的窗口。通过定义回调函数_MyCallback,作者详细展示了获取窗口句柄、窗口类名和窗口文本的步骤。最后,代码演示了查找指定标题的窗口并打印其句柄。这是一个关于Windows API和Python结合的实用示例。
摘要由CSDN通过智能技术生成

代码虽然简单,还要做一下小记,

以后用的到

import win32gui, win32con, win32api

import time, math, random

def _MyCallback( hwnd, extra ):

windows = extra

temp=[]

temp.append(hex(hwnd))

temp.append(win32gui.GetClassName(hwnd))

temp.append(win32gui.GetWindowText(hwnd))

windows[hwnd] = temp

def TestEnumWindows():

windows = {}

win32gui.EnumWindows(_MyCallback, windows)

print "Enumerated a total of windows with %d classes" ,(len(windows))

print '------------------------------'

#print classes

print '-------------------------------'

for item in windows :

print windows[item]

print "Enumerating all windows..."

h=win32gui.FindWindow(None,'\xba\xec\xce\xe5')

print hex(h)

#TestEnumWindows()

print "All tests done!"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值