__author__ = 'Administrator'
本文件演如何使用win32gui來遍歷系統(tǒng)中所有的頂層窗口,
from pprint import pprint
return s.decode('gbk').encode('utf-8')
def show_window_attr(hWnd):
#中文系統(tǒng)默認(rèn)title是gb2312的編碼
title = win32gui.GetWindowText(hWnd)
clsname = win32gui.GetClassName(hWnd)
print '窗口句柄:%s ' % (hWnd)
print '窗口標(biāo)題:%s' % (title)
print '窗口類名:%s' % (clsname)
def show_windows(hWndList):
win32gui.EnumWindows(lambda hWnd, param: param.append(hWnd), hWndList)
def demo_child_windows(parent):
win32gui.EnumChildWindows(parent, lambda hWnd, param: param.append(hWnd), hWndChildList)
show_windows(hWndChildList)
hWndList = demo_top_windows()
#這里系統(tǒng)的窗口好像不能直接遍歷,不知道是否是權(quán)限的問題
hWndChildList = demo_child_windows(parent)
print('-----top windows-----')
print('-----sub windows:from %s------' % (parent))