__author__ = 'Administrator'
本文件演如何使用win32gui来遍历系统中所有的顶层窗口,
from pprint import pprint
return s.decode('gbk').encode('utf-8')
def show_window_attr(hWnd):
title = win32gui.GetWindowText(hWnd)
clsname = win32gui.GetClassName(hWnd)
print '窗口句柄:%s ' % (hWnd)
print '窗口标题:%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()
#这里系统的窗口好像不能直接遍历,不知道是否是权限的问题
hWndChildList = demo_child_windows(parent)
print('-----top windows-----')
print('-----sub windows:from %s------' % (parent))