Python win32gui 模块,FindWindow() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用win32gui.FindWindow()

项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
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))

#???????->?????
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
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))

#?????
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
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))
#????
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
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)
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
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))
项目:ATX    作者:NetEaseGame    | 项目源码 | 文件源码
def __init__(self, window_name=None, exe_file=None, exclude_border=True):
        hwnd = 0

        # first check window_name
        if window_name is not None:
            hwnd = win32gui.FindWindow(None, window_name)
            if hwnd == 0:
                def callback(h, extra):
                    if window_name in win32gui.GetWindowText(h):
                        extra.append(h)
                    return True
                extra = []
                win32gui.EnumWindows(callback, extra)
                if extra: hwnd = extra[0]
            if hwnd == 0:
                raise WindowsAppNotFoundError("Windows Application <%s> not found!" % window_name)

        # check exe_file by checking all processes current running.
        elif exe_file is not None:
            pid = find_process_id(exe_file)
            if pid is not None:
                def callback(h, extra):
                    if win32gui.IsWindowVisible(h) and win32gui.IsWindowEnabled(h):
                        _, p = win32process.GetWindowThreadProcessId(h)
                        if p == pid:
                            extra.append(h)
                        return True
                    return True
                extra = []
                win32gui.EnumWindows(callback, extra)
                #TODO: get main window from all windows.
                if extra: hwnd = extra[0]
            if hwnd == 0:
                raise WindowsAppNotFoundError("Windows Application <%s> is not running!" % exe_file)

        # if window_name & exe_file both are None, use the screen.
        if hwnd == 0:
            hwnd = win32gui.GetDesktopWindow()

        self.hwnd = hwnd
        self.exclude_border = exclude_border
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
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)
项目:chat-robot    作者:wdc63    | 项目源码 | 文件源码
def enter():
    time.sleep(2)
    appname = "?????"
    enter = 0x0D
    window = win32gui.FindWindow(None, appname)
    try:
        win32gui.SetForegroundWindow(window)
    except:
        pass
    win32api.keybd_event(enter,0,0,0)
    time.sleep(0.1)
    win32api.keybd_event(enter,0,0,0)
    time.sleep(0.1)
    win32api.keybd_event(enter,0,0,0)
    time.sleep(0.1)
    win32api.keybd_event(enter,0,0,0)
    time.sleep(0.1)
    win32api.keybd_event(enter,0,0,0)
    time.sleep(0.1)
项目:chat-robot    作者:wdc63    | 项目源码 | 文件源码
def hawk_enter():
    appname = "?????"
    enter = 0x0D
    count = 0
    while True:
        if count % 10 == 0:
            window = win32gui.FindWindow(None, appname)
            try:
                win32gui.SetForegroundWindow(window)
            except:
                pass
        if window != 0:
            win32api.keybd_event(enter,0,0,0)
            time.sleep(0.05)
            win32api.keybd_event(enter,0 ,win32con.KEYEVENTF_KEYUP ,0)
        time.sleep(1)
        count += 1
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
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)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
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)
项目:robotframework-weblibrary    作者:Netease-AutoTest    | 项目源码 | 文件源码
def web_upload_file(self, filepath):
        """????(??flash????)

        filepath ?????????????????????????${CURDIR}${/}Res${/}Plus_Web${/}pic0.jpg
        ${CURDIR}????????????
        RF?filepath???????unicode
        ??????????????????????????????????
        | Web Upload File | ${filepath} |   
        | Web Upload File | ${CURDIR}${/}Res${/}Plus_Web${/}pic0.jpg |  
        """
        filepath=os.path.abspath(filepath)
        change = str(filepath)
        time.sleep(1)
        self._handle = win32gui.FindWindow(None, u"??")#??“??”?????
        win32gui.SetForegroundWindow(self._handle)#??????
        SendKeys.SendKeys(change)
        time.sleep(1)
        SendKeys.SendKeys("{ENTER}")
项目:garden.notification    作者:kivy-garden    | 项目源码 | 文件源码
def _hide_w32_window(self):
        try:
            w32win = win32gui.FindWindow(None, self.title)
            win32gui.ShowWindow(w32win, SW_HIDE)
            win32gui.SetWindowLong(
                w32win,
                GWL_EXSTYLE,
                win32gui.GetWindowLong(
                    w32win, GWL_EXSTYLE) | WS_EX_TOOLWINDOW
            )
            win32gui.ShowWindow(w32win, SW_SHOW)
            self._return_focus_w32()
        except Exception:
            tb = traceback.format_exc()
            Logger.error(
                'Notification: An error occured in {}\n'
                '{}'.format(self.title, tb)
            )
项目:AutoTestFramework    作者:huilansame    | 项目源码 | 文件源码
def upload_by_autoit(self, files):
        """autoit?? —— ???????????????????files????list?"""
        self._window_open()
        self._files(files)
        self.logger.info('upload {} by autoit'.format(self.files))

        # ????????
        if win32gui.FindWindow('#32770', self.window_name):
            self.window_open_flag = 1
        else:
            raise UploadWindowNotOpenError('???????????')

        upfile = os.path.abspath(DefaultConfig().base_path + '\\src\\resource\\' + AUTOITEXE[self.driver.name])
        os.system('{0} {1}'.format(upfile, self.files))  # ??exe?????

        self.window_open_flag = 0

    # ??????
项目:Automation-Framework-for-devices    作者:tok-gogogo    | 项目源码 | 文件源码
def GetChildapp(self,str_app):
        print '******** GetChildapp fuction ********'
        hwnd = win32gui.FindWindow(None, str_app)
        if hwnd < 1:
            hwnd = self.find_main_window(str_app)
        if hwnd>1:
            hChild =  win32gui.GetWindow(hwnd,win32con.GW_CHILD)
            bufLen=1024
            buf =win32gui.PyMakeBuffer(bufLen)
            totalnum = 1 
            while hChild :
                hChild = win32gui.GetWindow(hChild,win32con.GW_HWNDNEXT)
                n = win32gui.SendMessage(hChild,win32con.WM_GETTEXT,bufLen,buf)
                str = buf[:n]
                print '@@@@@@@@@@@'
                print win32gui.GetWindowText(hChild)
                print str
                '''
                if totalnum ==3:
                    win32gui.SendMessage(hChild,win32con.WM_SETTEXT,None,'Realtek 10/100/1000 Ethernet NIC')
                '''
                print  totalnum,hChild
                totalnum = totalnum + 1

        print '******** GetChildapp fuction ********',totalnum
项目:Automation-Framework-for-devices    作者:tok-gogogo    | 项目源码 | 文件源码
def Mouse_LB_Double(self,str_app,lb_dx,lb_dy,Flag='1'):
        time.sleep(1)
        tmp=(string.atoi(lb_dx),string.atoi(lb_dy))
        hwnd = win32gui.FindWindow(None, str_app)
        print 'Mouse_RB str_app,hwnd ',str_app,hwnd
        if hwnd < 1:
            hwnd = self.find_main_window(str_app)

        win32api.SetCursorPos(tmp)

        time.sleep(1)
        #win32api.SetDoubleCIckTime()
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,tmp[0], tmp[1]) 
        time.sleep(0.005)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,tmp[0], tmp[1])
        time.sleep(0.005)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,tmp[0], tmp[1]) 
        time.sleep(0.005)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,tmp[0], tmp[1])
        time.sleep(0.005)
        return True
项目:Automation-Framework-for-devices    作者:tok-gogogo    | 项目源码 | 文件源码
def Mouse_RB(self,str_app,lb_dx,lb_dy,Flag='1'):
        print "*********Mouse_RB function**********"
        time.sleep(1)
        tmp=(string.atoi(lb_dx),string.atoi(lb_dy))
        hwnd = win32gui.FindWindow(None, str_app)
        print 'Mouse_RB str_app,hwnd ',str_app,hwnd
        if hwnd < 1:
            hwnd = self.find_main_window(str_app)
            #win32gui.ShowWindow(hwnd, 0)
        win32api.SetCursorPos(tmp)
        print 'Mouse_RB tmp =',tmp
        if Flag == '1':
            time.sleep(1)
            win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,tmp[0], tmp[1]) 
            time.sleep(0.05)
            win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,tmp[0], tmp[1])
            time.sleep(0.05)
        return True
项目:Automation-Framework-for-devices    作者:tok-gogogo    | 项目源码 | 文件源码
def Mouse_LB(self,str_app,lb_dx,lb_dy,Flag='1'):
        print "*********Mouse_LB function**********"
        time.sleep(1)
        tmp=(string.atoi(lb_dx),string.atoi(lb_dy))
        hwnd = win32gui.FindWindow(None, str_app)
        if hwnd < 1:
            hwnd = self.find_main_window(str_app)
            #win32gui.ShowWindow(hwnd, 0)
            win32api.SetCursorPos(tmp)
            print 'Mouse_LB tmp =',tmp
            if Flag == '1':
                time.sleep(1)
                win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,tmp[0], tmp[1]) 
                time.sleep(0.05)
                win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,tmp[0], tmp[1])
                time.sleep(0.05)
        return True
项目:Automation-Framework-for-devices    作者:tok-gogogo    | 项目源码 | 文件源码
def omnipeek_close(self):

        print 'Close the omnipeek application software'
        hwnd = win32gui.FindWindow('OmniPeek',None) 
        win32gui.SetForegroundWindow(hwnd)
        self.shortcut_keys(['Alt','F'])
        self.sleep('1')
        self.shortcut_keys(['X'])
        self.sleep('1')

        hwd = win32gui.FindWindow(None,'OmniPeek')
        #print hwd
        #The window exist
        if hwd:
            win32gui.SetForegroundWindow(hwd)    #ö
            self.sleep('1')
            self.shortcut_keys(['Alt','Y'])
            self.sleep('5')

        return True
项目:Automation-Framework-for-devices    作者:tok-gogogo    | 项目源码 | 文件源码
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
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
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))

#????
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
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))

#???
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
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))

#??
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
def Open_TDX():
    try:
        handle = win32process.CreateProcess(path+'TdxW.exe','',None,None,0,win32process.CREATE_NO_WINDOW,None,path,win32process.STARTUPINFO())#??TB,?????
        time.sleep(3)
        TDX_handle = win32gui.FindWindow('#32770','???????V7.35')
    except Exception as e:
        ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))

#????
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
def Info():
    try:
        win32gui.PostMessage(win32gui.FindWindow('#32770','?????'),win32con.WM_CLOSE,0,0)
        time.sleep(5)
    except Exception as e:
        ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
#???? Ctrl+T
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
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))
#????
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
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))
#?????
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
def Close_Stockpickingmachine():
    time.sleep(5)
    try:
        #while win32gui.FindWindowEx(win32gui.FindWindow('#32770','????'),None,'Static','????. ') == 0:
            print("????")
            time.sleep(1)
            #if win32gui.FindWindowEx(win32gui.FindWindow('#32770','????'),None,'Static','????. ') != 0:
            win32gui.PostMessage(win32gui.FindWindow('#32770','????'),win32con.WM_CLOSE,0,0)
            time.sleep(3)
            print("????")
                #break
    except Exception as e:
        ReadEBK.wx_msg(corp_id, secret,agentid,sys._getframe().f_code.co_name+'\t'+str(e))
项目:tdx    作者:sqltxt    | 项目源码 | 文件源码
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))
项目:OpenAI_Challenges    作者:AlwaysLearningDeeper    | 项目源码 | 文件源码
def grab_screen(region=None, title=None):
    hwin = win32gui.GetDesktopWindow()
    if region:
        left,top,x2,y2 = region
        width = x2 - left + 1
        height = y2 - top + 1
    elif title:
        gtawin = win32gui.FindWindow(None, title)
        if not gtawin:
            raise Exception('window title not found')
        #get the bounding box of the window
        left, top, x2, y2 = win32gui.GetWindowRect(gtawin)
        width = x2 - left +1
        height = y2 - top +1
    else:
        width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
        height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
        left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
        top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)

    hwindc = win32gui.GetWindowDC(hwin)
    srcdc = win32ui.CreateDCFromHandle(hwindc)
    memdc = srcdc.CreateCompatibleDC()
    bmp = win32ui.CreateBitmap()
    bmp.CreateCompatibleBitmap(srcdc, width, height)
    memdc.SelectObject(bmp)
    memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)

    signedIntsArray = bmp.GetBitmapBits(True)
    img = np.fromstring(signedIntsArray, dtype='uint8')
    img.shape = (height,width,4)

    srcdc.DeleteDC()
    memdc.DeleteDC()
    win32gui.ReleaseDC(hwin, hwindc)
    win32gui.DeleteObject(bmp.GetHandle())

    return cv2.cvtColor(img, cv2.COLOR_BGRA2RGB)
项目:Yugioh-bot    作者:will7200    | 项目源码 | 文件源码
def is_process_running(self):
        try:
            if win32gui.FindWindow(None, "Nox") or win32gui.FindWindow(None, "NoxPlayer"):
                return True
        except:
            return False
项目:AutomatorX    作者:xiaoyaojjian    | 项目源码 | 文件源码
def __init__(self, window_name=None, exe_file=None, exclude_border=True):
        hwnd = 0

        # first check window_name
        if window_name is not None:
            hwnd = win32gui.FindWindow(None, window_name)
            if hwnd == 0:
                def callback(h, extra):
                    if window_name in win32gui.GetWindowText(h):
                        extra.append(h)
                    return True
                extra = []
                win32gui.EnumWindows(callback, extra)
                if extra: hwnd = extra[0]
            if hwnd == 0:
                raise WindowsAppNotFoundError("Windows Application <%s> not found!" % window_name)

        # check exe_file by checking all processes current running.
        elif exe_file is not None:
            pid = find_process_id(exe_file)
            if pid is not None:
                def callback(h, extra):
                    if win32gui.IsWindowVisible(h) and win32gui.IsWindowEnabled(h):
                        _, p = win32process.GetWindowThreadProcessId(h)
                        if p == pid:
                            extra.append(h)
                        return True
                    return True
                extra = []
                win32gui.EnumWindows(callback, extra)
                #TODO: get main window from all windows.
                if extra: hwnd = extra[0]
            if hwnd == 0:
                raise WindowsAppNotFoundError("Windows Application <%s> is not running!" % exe_file)

        # if window_name & exe_file both are None, use the screen.
        if hwnd == 0:
            hwnd = win32gui.GetDesktopWindow()

        self.hwnd = hwnd
        self.exclude_border = exclude_border
项目:myautotest    作者:auuppp    | 项目源码 | 文件源码
def find_window(self, class_name, window_name = None):
        """Pass a window class name & window name directly if known to get the window """
        self._handle = win32gui.FindWindow(class_name, window_name)
项目:Spotilyrics    作者:eitchtee    | 项目源码 | 文件源码
def getwindow(Title="SpotifyMainWindow"):
    window_id = win32gui.FindWindow(Title, None)
    return window_id
项目:pyaimp    作者:EpocDotFr    | 项目源码 | 文件源码
def _get_aimp_window(self):
        """Find the AIMP window handler who provides the remote API calls endpoint.

        :raises RuntimeError: The AIMP window cannot be found.
        :rtype: None
        """
        self._aimp_window = win32gui.FindWindow(AIMPRemoteAccessClass, None)

        if not self._aimp_window:
            raise RuntimeError('Unable to find the AIMP window. Are you sure it is running?')
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def new_icon(hdesk,desktop_name):
    """ Runs as a thread on each desktop to create a new tray icon and handle its messages """ 
    global id
    id=id+1
    hdesk.SetThreadDesktop()
    ## apparently the threads can't use same hinst, so each needs its own window class
    windowclassname='PythonDesktopManager'+desktop_name
    wc = win32gui.WNDCLASS()
    wc.hInstance = win32api.GetModuleHandle(None)
    wc.lpszClassName = windowclassname
    wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW | win32con.CS_GLOBALCLASS
    wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW )
    wc.hbrBackground = win32con.COLOR_WINDOW
    wc.lpfnWndProc = icon_wndproc
    windowclass = win32gui.RegisterClass(wc)
    style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
    hwnd = win32gui.CreateWindow(windowclass, 'dm_'+desktop_name, win32con.WS_SYSMENU,
                    0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
                    0, 0, wc.hInstance, None)
    win32gui.UpdateWindow(hwnd)
    flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
    notify_info = (hwnd, id, flags, win32con.WM_USER+20, hicon, 'Desktop Manager (%s)' %desktop_name)
    window_info[hwnd]=notify_info
    ## wait for explorer to initialize system tray for new desktop
    tray_found=0
    while not tray_found:
        try:
            tray_found=win32gui.FindWindow("Shell_TrayWnd",None)
        except win32gui.error:
            traceback.print_exc
            time.sleep(.5)
    win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, notify_info)
    win32gui.PumpMessages()
项目:CNKI-QQFriend    作者:hsluoyz    | 项目源码 | 文件源码
def QQ_SendTextWithAt(str):
    os.system(qq_shortcut)

    try_time = 0
    while True:
        time.sleep(0.5)
        hwnd = win32gui.FindWindow(None, '??&??')
        # hwnd = win32gui.FindWindow(None, 'OSVT?O?')
        print('try_time = %d, hwnd = %d' % (try_time, hwnd))
        if hwnd != 0:
            break
        elif try_time >= 60:
            print ('SendTextToQQ Error.')
            return
        else:
            try_time = try_time + 1

    win32gui.SetForegroundWindow(hwnd)

    QQ_PrintTextWithAt(str)
    QQ_Enter()

    # win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
    # win32gui.PostMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
    # win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, ord('v'), 0)
    # win32gui.PostMessage(hwnd, win32con.WM_KEYUP, ord('v'), 0)


    #win32gui.SendMessage(hwnd, win32con.WM_SETTEXT, None, 'aaa')
    #win32gui.SetWindowText(hwnd, 'aaa')
    #win32gui.ReplaceSel()
    #win32gui.PostMessage(hwnd, win32con.WM_CHAR, '', 3)

    # win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_CONTROL, 0)
    # win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, ord('V'), 0)
    # win32gui.PostMessage(hwnd, win32con.WM_KEYUP, ord('V'), 0)
    # win32gui.PostMessage(hwnd, win32con.WM_KEYUP, win32con.VK_CONTROL, 0)
项目:CNKI-QQFriend    作者:hsluoyz    | 项目源码 | 文件源码
def QQ_checkTargetWindow():
    window_name = '?0'
    hwnd = win32gui.FindWindow(None, window_name)
    if hwnd == 0:
        return 0
    else:
        print "find window = " + window_name.decode('gbk')
        return hwnd
项目:poeai    作者:nicholastoddsmith    | 项目源码 | 文件源码
def GetHWND(self, wname = None):
        '''
        Gets handle of window to view
        wname:         Title of window to find
        Return:        True on success; False on failure
        '''
        if wname is None:
            self.hwnd = win32gui.GetDesktopWindow()
        else:
            self.hwnd = win32gui.FindWindow(None, wname)    
        if self.hwnd == 0:
            self.hwnd = None
            return False
        self.l, self.t, self.r, self.b = win32gui.GetWindowRect(self.hwnd)
        return True
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def new_icon(hdesk,desktop_name):
    """ Runs as a thread on each desktop to create a new tray icon and handle its messages """ 
    global id
    id=id+1
    hdesk.SetThreadDesktop()
    ## apparently the threads can't use same hinst, so each needs its own window class
    windowclassname='PythonDesktopManager'+desktop_name
    wc = win32gui.WNDCLASS()
    wc.hInstance = win32api.GetModuleHandle(None)
    wc.lpszClassName = windowclassname
    wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW | win32con.CS_GLOBALCLASS
    wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW )
    wc.hbrBackground = win32con.COLOR_WINDOW
    wc.lpfnWndProc = icon_wndproc
    windowclass = win32gui.RegisterClass(wc)
    style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
    hwnd = win32gui.CreateWindow(windowclass, 'dm_'+desktop_name, win32con.WS_SYSMENU,
                    0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
                    0, 0, wc.hInstance, None)
    win32gui.UpdateWindow(hwnd)
    flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
    notify_info = (hwnd, id, flags, win32con.WM_USER+20, hicon, 'Desktop Manager (%s)' %desktop_name)
    window_info[hwnd]=notify_info
    ## wait for explorer to initialize system tray for new desktop
    tray_found=0
    while not tray_found:
        try:
            tray_found=win32gui.FindWindow("Shell_TrayWnd",None)
        except win32gui.error:
            traceback.print_exc
            time.sleep(.5)
    win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, notify_info)
    win32gui.PumpMessages()
项目:RobotTrader    作者:JaySinco    | 项目源码 | 文件源码
def __init__(self, ????Name, reSetSelfWindow=False):
        # ?????????
        if reSetSelfWindow:
            ???hwnd = win32gui.FindWindow("ConsoleWindowClass", r"D:\ProgramFiles\Anaconda3\python.exe")
            win32gui.SetWindowPos(???hwnd, win32con.HWND_TOP, 0,370,800,350, win32con.SWP_SHOWWINDOW) 
        # ??????????
        self.????hwnd = win32gui.FindWindow("ConsoleWindowClass", ????Name)
        if not self.????hwnd:
            raise RuntimeError('????"{}"???!'.format(????Name))
        win32gui.SetWindowPos(self.????hwnd, win32con.HWND_TOP, 0,0,800,350, win32con.SWP_SHOWWINDOW) 
        # ??????
        self.cmdFM = CmdFileMap()
项目:autoxd    作者:nessessary    | 项目源码 | 文件源码
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
项目:spotifylyrics    作者:fr31    | 项目源码 | 文件源码
def getwindowtitle():
    if sys.platform == "win32":
        spotify = win32gui.FindWindow('SpotifyMainWindow', None)
        windowname = win32gui.GetWindowText(spotify)
    elif sys.platform == "darwin":
        windowname = ''
        try:
            command = "osascript getCurrentSong.AppleScript"
            windowname = subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8")
        except Exception:
            pass
    else:
        windowname = ''
        session = dbus.SessionBus()
        spotifydbus = session.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
        spotifyinterface = dbus.Interface(spotifydbus, "org.freedesktop.DBus.Properties")
        metadata = spotifyinterface.Get("org.mpris.MediaPlayer2.Player", "Metadata")
        try:
            command = "xwininfo -tree -root"
            windows = subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8")
            spotify = ''
            for line in windows.splitlines():
                if '("spotify" "Spotify")' in line:
                    if " - " in line:
                        spotify = line
                        break
            if spotify == '':
                windowname = 'Spotify'
        except Exception:
            pass
        if windowname != 'Spotify':
            windowname = "%s - %s" %(metadata['xesam:artist'][0], metadata['xesam:title'])
    if "—" in windowname:
        windowname = windowname.replace("—", "-")
    if "Spotify - " in windowname:
        windowname = windowname.strip("Spotify - ")
    return(windowname)
项目:pyAutoTrading    作者:drongh    | 项目源码 | 文件源码
def findTopWindow(wantedText=None, wantedClass=None):
    """
    :param wantedText: ????
    :param wantedClass: ????
    :return: ?????????
    """
    return win32gui.FindWindow(wantedClass, wantedText)
项目:autoops_for_win    作者:qiueer    | 项目源码 | 文件源码
def GetWinByTitle(cls, clsname=None, win_title=None, is_foreground=True):
        """
        FindWindow? ????
        """
        whd = 0
        if clsname and win_title:
            whd=win32gui.FindWindow(clsname, win_title)
        elif clsname:
            whd=win32gui.FindWindow(clsname, None)
        elif win_title:
            whd=win32gui.FindWindow(None, win_title)
        if whd and is_foreground == True:
            cls.SetAsForegroundWindow(whd)
        return whd
项目:YOHO_Automated_Test    作者:yzwy1988    | 项目源码 | 文件源码
def find_window(self, class_name, window_name=None):
        """Pass a window class name & window name directly if known to get the window """
        self._handle = win32gui.FindWindow(class_name, window_name)
项目:easytrader    作者:yuzhucu    | 项目源码 | 文件源码
def _has_login_window(self):
        for title in [' - ????', ' - ???? - ????']:
            self.login_hwnd = win32gui.FindWindow(None, title)
            if self.login_hwnd != 0:
                return True
        return False
项目:audio-visualizer-screenlet    作者:ninlith    | 项目源码 | 文件源码
def __init__(self, title):
        self.topmost = not self.is_desktop_on_foreground()
        self.hwnd = win32gui.FindWindow(None, title)
项目:garden.notification    作者:kivy-garden    | 项目源码 | 文件源码
def _return_focus_w32(self):
        w32win = win32gui.FindWindow(None, KWARGS['parent_title'])
        win32gui.SetForegroundWindow(w32win)
项目:garden.notification    作者:kivy-garden    | 项目源码 | 文件源码
def taskbar():
    if platform == 'win':
        # example:
        # right side  x>0  y=0    (1474,   0, 1536, 864)
        # left side   x=0  y<R/2  (   0,   0,   62, 864)
        # top side    x=0  y=0    (   0,   0, 1536,  27)
        # bot side    x=0  y>R/2  (   0, 837, 1536, 864)

        # get resolution to get taskbar position
        res = sys_resolution()

        # get taskbar rectangle
        handle = win32gui.FindWindow("Shell_traywnd", None)
        left, top, right, bottom = win32gui.GetWindowRect(handle)

        x = y = 0
        width, height = res

        if left:
            pos = 'right'
            x = left
            width = right - left
        elif right < res['y'] / 2.0:
            pos = 'left'
            width = right
        elif right > res['y'] / 2.0 and not top:
            pos = 'top'
            height = bottom
        elif right > res['y'] / 2.0 and top:
            pos = 'bottom'
            y = top
            height = bottom - top
    else:
        x, y, width, height, pos = (0, 0, 0, 0, '')

    return {
        'x': x, 'y': y,
        'width': width, 'height': height,
        'pos': pos
    }