win32gui.EnumWindows

python2

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!"

python3

import win32gui
def _MyCallback(hwnd, extra):
    windows = extra
    temp = []
    temp.append(hex(hwnd))
    temp.append(win32gui.GetClassName(hwnd))
    temp.append(win32gui.GetWindowText(hwnd))
    windows[hwnd] = temp
windows = {}
win32gui.EnumWindows(_MyCallback, windows)
hld=win32gui.FindWindow("TXGuiFoundation",'实时加速工具')

hldb=win32gui.FindWindow("TXGuiFoundation",'实时加速工具2')

img

import win32gui


def _MyCallback(hwnd, extra):
    windows = extra
    temp = []
    temp.append(hex(hwnd))
    temp.append(win32gui.GetClassName(hwnd))
    temp.append(win32gui.GetWindowText(hwnd))
    windows[hwnd] = temp


windows = {}
win32gui.EnumWindows(_MyCallback, windows)
hld = win32gui.FindWindow("TXGuiFoundation", '实时加速工具')

hldb = win32gui.FindWindow("TXGuiFoundation", '实时加速工具2')
"""
手动确定ClassName-WindowText  窗口组名-单独名
生成临时文件,检索
with open('tmp.txt', 'w', encoding='utf-8') as fo:
    for i in windows:
        s = '%s%s' % (str(i), str(windows[i]))
        fo.write(s)
"""
"""
8064026['0x7b0c1a', 'BS2CHINAUI', '']
201748['0x31414', 'BS2CHINAUI', 'BSCNKEYMAPWND_Android']
660380['0xa139c', 'BS2CHINAUI', '']
529522['0x81472', 'BS2CHINAUI', '']
922564['0xe13c4', 'BS2CHINAUI', 'BlueStacks App Player']

4390956['0x43002c', 'BS2CHINAUI', 'soui tooltip']
988220['0xf143c', 'BS2CHINAUI', 'soui tooltip']
660518['0xa1426', 'BS2CHINAUI', 'soui tooltip']

"""

windowstext = 'BlueStacks App Player'

hld_a,hld_b = win32gui.FindWindow('BS2CHINAUI', 'BSCNKEYMAPWND_Android'),win32gui.FindWindow('BS2CHINAUI', 'BlueStacks App Player')
posted @ 2019-09-09 08:52  支照  阅读(6187)  评论(0编辑  收藏  举报