我们从Python开源项目中,提取了以下38个代码示例,用于说明如何使用win32gui.FindWindowEx()。
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)) #???????->?????
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 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
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
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
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
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
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
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
def config_log(self,log_name): print 'Control button: Log File' hwd = win32gui.FindWindow(None,"PingTest") hwd_butten = win32gui.FindWindowEx(hwd, None, 'Button', 'Log File:') #print hwd_butten self.Mouse_LB_click(hwd_butten) self.sleep('1') list_1 = '' sep = '\\' list_1 = log_name.split(sep) list_1.pop() file_name = sep.join(list_1) if os.path.exists(file_name) == False: msg = "Path does not exist not exists , I will help you mkdir this path:"+file_name print msg log_public(msg) os.mkdir(file_name) #log_name???log_name if log_name == '': path1 = os.path.abspath(sys.argv[0]) str=path1.split('\\') path_parent=str[0] self.dst=path_parent +'\\result_' log_name = log_name +'_'+time.strftime(KEY_TIME_FORMAT)+'.txt' print 'To save the log to:',log_name try: self.input_msg('6',log_name) except: log_public(ERR_PING_TEST_0003) self.m_ERROR_MSG = ERR_PING_TEST_0003 return False return True
def FindWindowByClassName(self, class_name): win_info = FX_WINDOW_INFO() win_info.Win32Window = win32gui.FindWindowEx(None, None, class_name, None) print(win_info.Win32Window) if win_info.Win32Window == 0: return None thread_process = win32process.GetWindowThreadProcessId(win_info.Win32Window) win_info.ProcessID = thread_process[1] win_info.ThreadID = thread_process[0] win_info.Title = win32gui.GetWindowText(win_info.Win32Window) return FX_Window(win_info)
def FindWindowByName(self, title_name): win_info = FX_WINDOW_INFO() win_info.Win32Window = win32gui.FindWindowEx(None, None, None, title_name) if win_info.Win32Window == 0: return None thread_process = win32process.GetWindowThreadProcessId(win_info.Win32Window) win_info.ProcessID = thread_process[1] win_info.ThreadID = thread_process[0] win_info.Title = win32gui.GetWindowText(win_info.Win32Window) return FX_Window(win_info)
def get_expect_window_label_text(self, _expect_sec_window): ''' Try to get window label text ''' # label_text = u"????" # label_text = label_text.encode('utf-8') # return label_text label_text = '' window = self.expect_sec_window child_control = None last_child = 0 while True: logging.debug("Find the child controls for parent window") child_control = win32gui.FindWindowEx(window, last_child, 'static', None) if not child_control: logging.debug("The child is None") break; else: logging.debug("The child is not None, ") buffer = win32gui.PyMakeBuffer(200) length = win32gui.SendMessage(child_control, win32con.WM_GETTEXT, 200, buffer) result = buffer[:length] result = result.decode('gbk').encode('utf-8') logging.debug("Got the child text is :" + result) last_child = child_control label_text = result time.sleep(0.5) def _winfun(hwnd, lparam): s = win32gui.GetWindowText(hwnd) s = s.decode('gbk').encode('utf-8') logging.debug("winfun, child_hwnd: %d txt: %s" % (hwnd, s)) return 1 if window: logging.debug("To enumerate all the child windows") win32gui.EnumChildWindows(self.expect_sec_window, _winfun, None) #bufferlength = struct.pack('i', 255) #count = win32gui.SendMessage(self.expect_sec_window, win32con.get, 0, 0) #for itemIndex in range(count): # value = array.array('c', bufferlength +str().ljust(253)) # valueLength = win32gui.SendMessage(self.expect_sec_window, getValueMessage, itemIndex, value) # yield value.tostring()[:valueLength] return label_text
def select_ssid(self): hwd0 = win32gui.FindWindow(WAVEQOE_CLASS,'WaveQoE - Real-World Deployment Tests: WaveQoE - 802.11ng_20.wml') #print hwd0 win32gui.SetForegroundWindow(hwd0) hwd1 = win32gui.FindWindowEx(hwd0, None, WAVEQOE_CLASS, 'qt_central_widget') #print hwd1 hwd2 = win32gui.FindWindowEx(hwd1, None, WAVEQOE_CLASS, 'splitter6') #print hwd2 hwd3 = win32gui.FindWindowEx(hwd2, None, WAVEQOE_CLASS, 'layout156') #print hwd3 hwd4 = win32gui.FindWindowEx(hwd3, None, WAVEQOE_CLASS, 'mainStack') print hwd4 hwd5 = win32gui.FindWindowEx(hwd4, None, WAVEQOE_CLASS, 'portSetup') print hwd5 hwd6 = win32gui.FindWindowEx(hwd5, None, WAVEQOE_CLASS, 'buttonGroup28') #print hwd6 #click Connect butten hwd7 = win32gui.FindWindowEx(hwd6, None, WAVEQOE_CLASS, 'chassisConnectBtn') #print hwd7 self.Mouse_LB_click(hwd7) time.sleep(5) #click Scan Channels butten hwd8 = win32gui.FindWindowEx(hwd6, None, WAVEQOE_CLASS, 'autoScanBtn') self.Mouse_LB_click(hwd8) time.sleep(30) #click Clients butten hwd9 = win32gui.FindWindowEx(hwd3, None, WAVEQOE_CLASS, 'groupBox35') #print hwd9 hwd10 = win32gui.FindWindowEx(hwd9, None, WAVEQOE_CLASS, 'mainToolBox') #print hwd10 ComboBox_list = findControls(hwd10,wantedClass = WAVEQOE_CLASS) #print ComboBox_list hwd11 = ComboBox_list[174] #print hwd11 self.Mouse_LB_click(hwd11) time.sleep(2) #select SSID self.click_CurrentPlace(lb_dx = '967',lb_dy = '228') self.click_CurrentPlace(lb_dx = '967',lb_dy = '228') self.click_CurrentPlace(lb_dx = '967',lb_dy = '228') time.sleep(1) self.click_CurrentPlace(lb_dx = '967',lb_dy = '247') time.sleep(1) return True #----------------------------------------------------------------------------- # Name: run_waveQoE # purpose: run waveQoE,begin the test. # explain: # Author: gongke # # Created: 2013/05/20 #-----------------------------------------------------------------------------
def Find_Gui_Tree(self,str_app='New Scenario',control_class='Button',filename='test_baidu',control_name='AfxOleControl'): print "*********Find_Gui_Tree function**********" time.sleep(1) #self.Mousepos_print() print 'str_app',str_app hwnd = win32gui.FindWindow(None, str_app) if hwnd < 1: hwnd = self.find_main_window(str_app) print 'hwnd',hwnd win32gui.SetForegroundWindow(hwnd) print 'hwnd :',hwnd,str_app win32gui.SetForegroundWindow(hwnd) #self.Mousepos_print('5') comboHwnd = win32gui.FindWindowEx(hwnd,0,control_class,None) print '111111111111comboHwnd',comboHwnd while comboHwnd: print "control_class:",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 str ''' if control_class in cla: n = win32gui.SendMessage(comboHwnd,win32con.WM_GETTEXT,bufLen,buf) str = buf[:n] print str 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) time.sleep(0.05) win32gui.SendMessage(comboHwnd,win32con.WM_LBUTTONUP,0) time.sleep(0.05) win32gui.SendMessage(win32con.WM_CLOSE,0,0) break ''' comboHwnd = win32gui.GetWindow(comboHwnd,win32con.GW_HWNDNEXT) time.sleep(1) return True
def select_ssid(self): hwd0 = win32gui.FindWindow(WAVEApps_CLASS,None) #print hwd0 win32gui.SetForegroundWindow(hwd0) hwd1 = win32gui.FindWindowEx(hwd0, None, WAVEApps_CLASS, 'qt_central_widget') #print hwd1 hwd2 = win32gui.FindWindowEx(hwd1, None, WAVEApps_CLASS, 'mainStack') #print hwd2 hwd3 = win32gui.FindWindowEx(hwd2, None, WAVEApps_CLASS, 'portSetup') #print hwd3 hwd4 = win32gui.FindWindowEx(hwd3, None, WAVEApps_CLASS, 'buttonGroup28') #print hwd4 #click Connect butten hwd5 = win32gui.FindWindowEx(hwd4, None, WAVEApps_CLASS, 'chassisConnectBtn') #print hwd5 self.Mouse_LB_click(hwd5) time.sleep(5) #click Scan Channels butten hwd6 = win32gui.FindWindowEx(hwd4, None, WAVEApps_CLASS, 'autoScanBtn') self.Mouse_LB_click(hwd6) time.sleep(30) #click Clients butten hwd7 = win32gui.FindWindowEx(hwd1, None, WAVEApps_CLASS, 'groupBox66') #print hwd7 hwd8 = win32gui.FindWindowEx(hwd7, None, WAVEApps_CLASS, 'mainToolBox') #print hwd8 ComboBox_list = findControls(hwd8,wantedClass = WAVEApps_CLASS) #print ComboBox_list hwd9 = ComboBox_list[130] #print hwd9 self.Mouse_LB_click(hwd9) time.sleep(2) #select SSID self.click_CurrentPlace(lb_dx = '1040',lb_dy = '226') self.click_CurrentPlace(lb_dx = '1040',lb_dy = '226') self.click_CurrentPlace(lb_dx = '1040',lb_dy = '226') time.sleep(1) self.click_CurrentPlace(lb_dx = '1040',lb_dy = '245') time.sleep(1) return True #----------------------------------------------------------------------------- # Name: run_waveApps # purpose: run waveApps,begin the test. # explain: # Author: gongke # # Created: 2013/05/20 #-----------------------------------------------------------------------------
def get_hwnd_by_title_class(self, class_text = None, title_text= None, parent_title = None,parent_class = None): """ Returns a windows window_handler Args: title_text (string): the title of the window we are looking for SPECIAL CASE: if "desktop:n" is given, a handle to the desktop number n handle is given Returns: int: the handler for the window if found Raises: win32.error: If the windowtitle is invalid """ if 'desktop:' in title_text.lower(): _ , num = title_text.lower().split(':',1) num = int(num) monitors = win32api.EnumDisplayMonitors() tar_mon = monitors[num] self.hwnd = tar_mon[1] return self.hwnd if title_text.lower() == "desktop": self.hwnd = win32gui.GetDesktopWindow() return self.hwnd child_hwnd = [] def child_enumerator(hwnd,param): child_hwnd.append(hwnd) return True if parent_title is not None or parent_class is not None: logging.debug("Where supplied title/class: {0}/{1}".format(str(title_text), str(class_text))) parent_hwnd = self.get_hwnd_by_title_class(class_text=parent_class,title_text=parent_title) win32gui.EnumChildWindows(parent_hwnd,child_enumerator,None) for hwnd in child_hwnd: hwnd_title = win32gui.GetWindowText(hwnd) hwnd_class = win32gui.GetClassName(hwnd) if (hwnd_title == title_text and title_text is not None) or \ (hwnd_class == class_text and class_text is not None): self.hwnd = hwnd return hwnd # logging.debug("Found parent with title/class {0}{1} at {2}".format(parent_title,parent_class,parent_hwnd)) # self.hwnd = win32gui.FindWindowEx(parent_hwnd,0,class_text,title_text) else: logging.debug("Where supplied title/class: {0}/{1}".format(str(title_text), str(class_text))) self.hwnd = win32gui.FindWindow(class_text, title_text) if self.hwnd == 0: raise ValueError('Unable to find a window with that title or class') logging.debug("Found window 0x{:2X}".format(self.hwnd)) return self.hwnd