def Menu():
try:
#??
pdhk=win32gui.GetWindowRect(win32gui.FindWindowEx(win32gui.FindWindow('TdxW_MainFrame_Class','???????V7.35 - [???-?????]'),None,'#32770',None))
win32api.SetCursorPos([pdhk[0]+330,pdhk[1]+10])
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0,0)
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0,0)
time.sleep(1)
#?????
win32api.SetCursorPos([pdhk[0]+380,pdhk[1]+20+480])
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0,0)
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0,0)
time.sleep(1)
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
#???????->?????
python类FindWindowEx()的实例源码
def Free_quotation():
time.sleep(3)
try:
Tab_handle = win32gui.FindWindowEx(win32gui.FindWindow('#32770','???????V7.35'),None,'SysTabControl32','Tab1')
#print(hex(Tab_handle))
#time.sleep(1)
p=win32gui.GetWindowRect(Tab_handle)
#print(p)
#print(p[2])
#print(p[3])
win32api.SetCursorPos([p[0]+170,p[1]+7])
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0,0)
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0,0)
time.sleep(1)
win32gui.PostMessage(win32gui.FindWindowEx(win32gui.FindWindow('#32770','???????V7.35'),None,'Button','??'),win32con.BM_CLICK,0,0)
time.sleep(3)
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
#?????
def Stock_option(Index):
try:
#tjxg = win32gui.FindWindow('#32770','????')
gs = win32gui.FindWindowEx(win32gui.FindWindow('#32770','????'),None,'ComboBox',None)
#time.sleep(1)
print(hex(gs))
win32gui.SendMessage(gs,win32con.CB_SHOWDROPDOWN,1,0) #??ComboBox???
time.sleep(1)
win32gui.SendMessage(gs,win32con.CB_SETCURSEL,Index,0)#???????
time.sleep(1)
win32gui.SendMessage(gs,win32con.WM_SETFOCUS,0,0)#????
time.sleep(1)
win32gui.SendMessage(gs,win32con.WM_KEYDOWN,0,0)#???????
time.sleep(1)
win32gui.SendMessage(gs,win32con.WM_KEYUP,0,0)
time.sleep(1)
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
#????
def TestObjectFromWindow():
# Check we can use ObjectFromLresult to get the COM object from the
# HWND - see KB Q249232
# Locating the HWND is different than the KB says...
hwnd = win32gui.FindWindow('IEFrame', None)
for child_class in ['TabWindowClass', 'Shell DocObject View',
'Internet Explorer_Server']:
hwnd = win32gui.FindWindowEx(hwnd, 0, child_class, None)
# ack - not working for markh on vista with IE8 (or maybe it is the
# lack of the 'accessibility' components mentioned in Q249232)
# either way - not working!
return
# But here is the point - once you have an 'Internet Explorer_Server',
# you can send a message and use ObjectFromLresult to get it back.
msg = win32gui.RegisterWindowMessage("WM_HTML_GETOBJECT")
rc, result = win32gui.SendMessageTimeout(hwnd, msg, 0, 0, win32con.SMTO_ABORTIFHUNG, 1000)
ob = pythoncom.ObjectFromLresult(result, pythoncom.IID_IDispatch, 0)
doc = Dispatch(ob)
# just to prove it works, set the background color of the document.
for color in "red green blue orange white".split():
doc.bgColor = color
time.sleep(0.2)
def Save():
try:
win32gui.PostMessage(win32gui.FindWindowEx(win32gui.FindWindow('#32770','???'),None,'Button','??(&S)'),win32con.BM_CLICK,0,0)
time.sleep(1)
global handle
handle = None
win32gui.EnumChildWindows(win32gui.FindWindow('#32770','?????'),handle_window,'?(&Y)')
if handle!= None:
win32gui.PostMessage(handle,win32con.BM_CLICK,0,0)
time.sleep(3)
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
def TestObjectFromWindow():
# Check we can use ObjectFromLresult to get the COM object from the
# HWND - see KB Q249232
# Locating the HWND is different than the KB says...
hwnd = win32gui.FindWindow('IEFrame', None)
for child_class in ['TabWindowClass', 'Shell DocObject View',
'Internet Explorer_Server']:
hwnd = win32gui.FindWindowEx(hwnd, 0, child_class, None)
# ack - not working for markh on vista with IE8 (or maybe it is the
# lack of the 'accessibility' components mentioned in Q249232)
# either way - not working!
return
# But here is the point - once you have an 'Internet Explorer_Server',
# you can send a message and use ObjectFromLresult to get it back.
msg = win32gui.RegisterWindowMessage("WM_HTML_GETOBJECT")
rc, result = win32gui.SendMessageTimeout(hwnd, msg, 0, 0, win32con.SMTO_ABORTIFHUNG, 1000)
ob = pythoncom.ObjectFromLresult(result, pythoncom.IID_IDispatch, 0)
doc = Dispatch(ob)
# just to prove it works, set the background color of the document.
for color in "red green blue orange white".split():
doc.bgColor = color
time.sleep(0.2)
def TestObjectFromWindow():
# Check we can use ObjectFromLresult to get the COM object from the
# HWND - see KB Q249232
# Locating the HWND is different than the KB says...
hwnd = win32gui.FindWindow('IEFrame', None)
for child_class in ['TabWindowClass', 'Shell DocObject View',
'Internet Explorer_Server']:
hwnd = win32gui.FindWindowEx(hwnd, 0, child_class, None)
# ack - not working for markh on vista with IE8 (or maybe it is the
# lack of the 'accessibility' components mentioned in Q249232)
# either way - not working!
return
# But here is the point - once you have an 'Internet Explorer_Server',
# you can send a message and use ObjectFromLresult to get it back.
msg = win32gui.RegisterWindowMessage("WM_HTML_GETOBJECT")
rc, result = win32gui.SendMessageTimeout(hwnd, msg, 0, 0, win32con.SMTO_ABORTIFHUNG, 1000)
ob = pythoncom.ObjectFromLresult(result, pythoncom.IID_IDispatch, 0)
doc = Dispatch(ob)
# just to prove it works, set the background color of the document.
for color in "red green blue orange white".split():
doc.bgColor = color
time.sleep(0.2)
def TestObjectFromWindow():
# Check we can use ObjectFromLresult to get the COM object from the
# HWND - see KB Q249232
# Locating the HWND is different than the KB says...
hwnd = win32gui.FindWindow('IEFrame', None)
for child_class in ['TabWindowClass', 'Shell DocObject View',
'Internet Explorer_Server']:
hwnd = win32gui.FindWindowEx(hwnd, 0, child_class, None)
# ack - not working for markh on vista with IE8 (or maybe it is the
# lack of the 'accessibility' components mentioned in Q249232)
# either way - not working!
return
# But here is the point - once you have an 'Internet Explorer_Server',
# you can send a message and use ObjectFromLresult to get it back.
msg = win32gui.RegisterWindowMessage("WM_HTML_GETOBJECT")
rc, result = win32gui.SendMessageTimeout(hwnd, msg, 0, 0, win32con.SMTO_ABORTIFHUNG, 1000)
ob = pythoncom.ObjectFromLresult(result, pythoncom.IID_IDispatch, 0)
doc = Dispatch(ob)
# just to prove it works, set the background color of the document.
for color in "red green blue orange white".split():
doc.bgColor = color
time.sleep(0.2)
def dumpWindow(hwnd, wantedText=None, wantedClass=None):
"""
:param hwnd: ????
:param wantedText: ??????
:param wantedClass: ???????
:return: ??????????????
"""
windows = []
hwndChild = None
while True:
hwndChild = win32gui.FindWindowEx(hwnd, hwndChild, wantedClass, wantedText)
if hwndChild:
textName = win32gui.GetWindowText(hwndChild)
className = win32gui.GetClassName(hwndChild)
windows.append((hwndChild, textName, className))
else:
return windows
ctrl_pingtest.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def config_PacketSize(self,time,step,Flag):
time = string.atoi(time)
step = string.atoi(step)
if Flag == 'Up':
print 'Increasing number of:',time,',increase the step:',step
elif Flag == 'Down':
print 'Reduceing number of:',time,',reduce the step:',step
hwd = win32gui.FindWindow(None,"PingTest")
edit_packet_up = win32gui.FindWindowEx(hwd, None, 'msctls_updown32', 'Spin1')
#print edit_packet_up
self.Mouse_LB_click(edit_packet_up)
self.shortcut_keys(['Down'])
self.sleep('1')
num = time * step
n = 1
while n <= num:
self.shortcut_keys([Flag])
n = n+1
return True
#type:Ping/Stop/Quit/Reset/Clear/Log File:/Error only
def CFQS():
try:
e = win32gui.GetWindowRect (win32gui.FindWindowEx(win32gui.FindWindowEx(win32gui.FindWindow('#32770','???????'),None,'#32770','???????'),None,'SysListView32','CFQS'))
win32api.SetCursorPos([e[0]+50,e[1]+25])
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0,0)
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0,0)
time.sleep(1)
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
#????
def Export_plate():
try:
win32gui.PostMessage(win32gui.FindWindowEx(win32gui.FindWindowEx(win32gui.FindWindow('#32770','???????'),None,'#32770','???????'),None,'Button','????'),win32con.BM_CLICK,0,0)
time.sleep(1)
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
#???
def File_name():
try:
win32gui.SendMessage(win32gui.FindWindowEx(win32gui.FindWindow('#32770','???'),None,'Edit',None),win32con.WM_SETTEXT,0,'????'+str(int(time.strftime("%Y%m%d")))+'.EBK')
time.sleep(1)
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
#??
def Join_condition():
try:
#time.sleep(5)
win32gui.PostMessage(win32gui.FindWindowEx(win32gui.FindWindow('#32770','????'),None,'Button','????'),win32con.BM_CLICK,0,0)
time.sleep(3)
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
#????
def EXE():
try:
while win32gui.FindWindowEx(win32gui.FindWindow('#32770','????'),None,'Static','????. ') == 0:
zs = win32gui.FindWindowEx(win32gui.FindWindow('#32770','????'),None,'Button','????')
print(zs)
print(type(zs))
win32gui.PostMessage(win32gui.FindWindowEx(win32gui.FindWindow('#32770','????'),None,'Button','????'),win32con.BM_CLICK,0,0)
time.sleep(7)
print("????")
break
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
#???
def Complement_data():
try:
time.sleep(3)
if win32gui.FindWindowEx(win32gui.FindWindow('#32770','TdxW'),None,'Button','?(&Y)') != 0:
win32gui.PostMessage(win32gui.FindWindowEx(win32gui.FindWindow('#32770','TdxW'),None,'Button','?(&Y)'),win32con.BM_CLICK,0,0)
time.sleep(5)
print("???")
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
#?????
def Close_TDX():
try:
time.sleep(3)
lstj=win32gui.FindWindow('TdxW_MainFrame_Class','???????V7.35 - [???-?????]')
print(hex(lstj))
win32gui.PostMessage(lstj,win32con.WM_CLOSE,0,0)
time.sleep(3)
win32gui.PostMessage(win32gui.FindWindowEx(win32gui.FindWindow('#32770','????'),None,'Button','??'),win32con.BM_CLICK,0,0)
time.sleep(3)
except Exception as e:
ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
def get_expect_sec_window(self):
'''return the expect window hwnd'''
# control = win32gui.FindWindowEx(window, 0, 'static', None)
# buffer = win32gui.PyMakeBuffer(20)
# length = win32gui.SendMessage(control, win32con.WM_GETTEXT, 20, buffer)
#
# result = buffer[:length]
# print result
# time.sleep(1)
return self.expect_sec_window
def __init__(self, pika_windowname, _score_address):
self.score_address = _score_address
self.hwnd = win32gui.FindWindowEx(0, 0, None, pika_windowname)
self.inputAction = action.action(_windowname=pika_windowname, _interval_time=self.interval_time)
self.stateReader = st.state(_hwnd=self.hwnd)
self.stateInit()
self.comScoreBuffer = 0
self.agentScoreBuffer = 0
self.comScoreOld = 0
self.agentScoreOld = 0
self.isGaming = False
self.flag = 10
self.isOpened = True
self.isFinished = True
self.memmoryReadThread = threading.Thread(target=self._asyncGetScoreValue)
self.pixelReadThread = threading.Thread(target=self._asyncGetState)
self.memmoryReadThread.start()
self.pixelReadThread.start()
def FindMainWindow():
win_caption = 'autoxd_frame'
hwnd = 0
for i in range(10):
if hwnd == 0:
hwnd = win32gui.FindWindow(None, win_caption)
if win32gui.IsWindowVisible(hwnd) == True:
break
hwnd = win32gui.FindWindowEx(0, hwnd , None, win_caption)
if win32gui.IsWindowVisible(hwnd) == True:
break
return hwnd
def GetComponent(cls, parent_whd=0, win_title=None, comp_cls_name=None, is_foreground=True):
"""
FindWindowEx? ???????????
?????????? GetComponent(u"??", parent_whd=whd)
?????????? GetComponent(comp_cls_name=u"Label", parent_whd=whd), ??Label???????????spy++???????????
"""
whd=win32gui.FindWindowEx(parent_whd, None, comp_cls_name, win_title)
if whd and is_foreground == True:
cls.SetAsForegroundWindow(whd)
return whd
def upload_by_win32(self, files):
"""win32?? —— ????????????????????files????list?"""
self._window_open()
self._files(files)
self.logger.info('upload {0} by win32'.format(self.files))
upload = win32gui.FindWindow('#32770', self.window_name)
# find Edit
ComboBoxEx32 = win32gui.FindWindowEx(upload, 0, 'ComboBoxEx32', None)
ComboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, 'ComboBox', None)
Edit = win32gui.FindWindowEx(ComboBox, 0, 'Edit', None)
# find confirm button
button = win32gui.FindWindowEx(upload, 0, 'Button', None)
# ????????
if upload and Edit and button:
self.window_open_flag = 1
else:
raise UploadWindowNotOpenError('???????????')
win32gui.SendMessage(Edit, win32con.WM_SETTEXT, 0, self.files)
win32gui.SendMessage(upload, win32con.WM_COMMAND, 1, button)
self.window_open_flag = 0
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
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
def Find_Gui_button(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)
#print 'hwnd :',hwnd,str_app
win32gui.SetForegroundWindow(hwnd)
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 (len(control_name ) ==0 and n==0) or ((len(control_name )>0 and str.find(control_name)>-1 )):
#win32gui.SendMessage(comboHwnd,win32con.WM_LBUTTONDOWN,0)
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)
#win32gui.SendMessage(win32con.WM_CLOSE,0,0)
#print '111'
result = True
break
comboHwnd = win32gui.GetWindow(comboHwnd,win32con.GW_HWNDNEXT)
time.sleep(1)
return result
ctrl_pingtest.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def control_butten_ping(self):
print 'Control button: Ping'
hwd = win32gui.FindWindow(None,"PingTest")
hwd_butten = win32gui.FindWindowEx(hwd, None, 'Button', 'Ping')
#print hwd_butten
self.Mouse_LB_click(hwd_butten)
self.sleep('1')
return True
ctrl_pingtest.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def control_butten_stop(self,ip):
print 'Control button: stop'
hwd = win32gui.FindWindow(None,ip)
hwd_butten = win32gui.FindWindowEx(hwd, None, 'Button', 'Stop')
#print hwd_butten
self.Mouse_LB_click(hwd_butten)
self.sleep('1')
return True
ctrl_pingtest.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def control_butten_quit(self):
print 'Control button: Quit'
hwd = win32gui.FindWindow(None,"PingTest")
hwd_butten = win32gui.FindWindowEx(hwd, None, 'Button', 'Quit')
#print hwd_butten
self.Mouse_LB_click(hwd_butten)
self.sleep('1')
return True
ctrl_pingtest.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def control_butten_clear(self):
print 'Control button: Clear'
hwd = win32gui.FindWindow(None,"PingTest")
hwd_butten = win32gui.FindWindowEx(hwd, None, 'Button', 'Clear')
#print hwd_butten
self.Mouse_LB_click(hwd_butten)
self.sleep('1')
return True
ctrl_pingtest.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def control_butten_status(self):
print 'Control button: status'
hwd = win32gui.FindWindow(None,"PingTest")
hwd_butten = win32gui.FindWindowEx(hwd, None, 'Button', 'Error only')
#print hwd_butten
self.Mouse_LB_click(hwd_butten)
self.sleep('1')
return True