def Find_Gui_title(self,str_app='Edit Action',find_control_class='0',control_class='WindowsForms10.Window.8.app.0.2e0c681',text='10',control_name=''):
time.sleep(1)
print "*********Find_Gui_title function**********"
#self.Mousepos_print()
print 'control_name:',str_app,find_control_class
hwnd = win32gui.FindWindow(None, str_app)
if hwnd < 1:
hwnd = self.find_main_window(str_app)
print 'hwnd :',hwnd,str_app
win32gui.SetForegroundWindow(hwnd)
comboHwnd = win32gui.FindWindowEx(hwnd,0,control_class,None)
print 'comboHwnd',comboHwnd
while comboHwnd:
cla = win32gui.GetClassName(comboHwnd)
print "control_class_name:",cla
bufLen=1024
buf =win32gui.PyMakeBuffer(bufLen)
n = win32gui.SendMessage(comboHwnd,win32con.WM_GETTEXT,bufLen,buf)
str = buf[:n]
print 'buf:',str
if str.find(find_control_class)>-1:
win32gui.PostMessage(comboHwnd,win32con.WM_LBUTTONDOWN,0)
time.sleep(0.05)
#win32gui.SendMessage(comboHwnd,win32con.WM_LBUTTONUP,0)
win32gui.PostMessage(comboHwnd,win32con.WM_LBUTTONUP,0)
time.sleep(0.05)
time.sleep(1)
break
comboHwnd = win32gui.GetWindow(comboHwnd,win32con.GW_HWNDNEXT)
return True
python类PostMessage()的实例源码
def Find_Gui_button_hwnd(self,str_app='´ò¿ª',control_class='Button',control_name='´ò¿ª(&O)'):
time.sleep(1)
result = False
print "*********Find_Gui_button function**********"
#self.Mousepos_print()
#print 'control_name:',str_app,',',control_name
hwnd = win32gui.FindWindow(None, str_app)
if hwnd < 1:
hwnd = self.find_main_window(str_app)
comboHwnd = win32gui.FindWindowEx(hwnd,0,control_class,None)
#print 'comboHwnd',comboHwnd
while comboHwnd:
#print "control_class:",comboHwnd,control_name
cla = win32gui.GetClassName(comboHwnd)
#print 'cla:' ,cla
bufLen=1024
buf =win32gui.PyMakeBuffer(bufLen)
if control_class in cla:
n = win32gui.SendMessage(comboHwnd,win32con.WM_GETTEXT,bufLen,buf)
str = buf[:n]
#print 'buttonname ,len,n,find :',str,len(control_name ),n,str.find(control_name)
if str.find(control_name)>-1:
result = True
win32gui.PostMessage(comboHwnd,win32con.WM_LBUTTONDOWN,0)
time.sleep(0.05)
#win32gui.SendMessage(comboHwnd,win32con.WM_LBUTTONUP,0)
win32gui.PostMessage(comboHwnd,win32con.WM_LBUTTONUP,0)
time.sleep(0.05)
time.sleep(1)
print 'find control_name',result
break
comboHwnd = win32gui.GetWindow(comboHwnd,win32con.GW_HWNDNEXT)
if result ==False:
comboHwnd = -1
return comboHwnd
ctrl_waveApps.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def init_PDF(self):
try:
hwnd1 = win32gui.FindWindow(PDF_CLASS,None)
except:
log_public(ERR_NO_0003)
self.m_ERROR_MSG = ERR_NO_0003
hwnd1 = 0
print 'hwnd1:',hwnd1
while hwnd1 != 0:
#close PDF window
time.sleep(2)
win32gui.PostMessage(hwnd1, win32con.WM_SYSCOMMAND, win32con.SC_CLOSE, 0);
print 'close_PDF'
try:
hwnd1 = win32gui.FindWindow(PDF_CLASS,None)
print 'new hwnd1---',hwnd1
except:
log_public(ERR_NO_0004)
self.m_ERROR_MSG = ERR_NO_0004
hwnd1 = 0
print 'new hwnd1:',hwnd1
else:
print 'hwnd1=0,init_PDF has been done'
return True
#-----------------------------------------------------------------------------
# Name: open_waveApps
# purpose: open waveApps.
# explain:
# Author: gongke
#
# Created: 2013/05/20
# Amend: 2013/07/05 ---yuanwen
#-----------------------------------------------------------------------------