zoukankan      html  css  js  c++  java
  • 激活浏览器窗口

    import win32.win32gui as win32gui
    import win32.lib.win32con as win32con
        class cWindow:
            def __init__(self):
                self._hwnd = None
    
            def SetAsForegroundWindow(self):
                # First, make sure all (other) always-on-top windows are hidden.
                # self.hide_always_on_top_windows()
                win32gui.SetForegroundWindow(self._hwnd)
    
            def Maximize(self):
                win32gui.ShowWindow(self._hwnd, win32con.SW_MAXIMIZE)
    
            def _window_enum_callback(self, hwnd, regex):
                '''Pass to win32gui.EnumWindows() to check all open windows'''
                if self._hwnd is None and re.match(regex, str(win32gui.GetWindowText(hwnd))) is not None:
                    self._hwnd = hwnd
    
            def find_window_regex(self, regex):
                self._hwnd = None
                win32gui.EnumWindows(self._window_enum_callback, regex)
    
            def hide_always_on_top_windows(self):
                win32gui.EnumWindows(self._window_enum_callback_hide, None)
    
            def _window_enum_callback_hide(self, hwnd, unused):
                if hwnd != self._hwnd:  # ignore self
                    # Is the window visible and marked as an always-on-top (topmost) window?
                    if win32gui.IsWindowVisible(hwnd) and win32gui.GetWindowLong(hwnd,
                                                                                 win32con.GWL_EXSTYLE) & win32con.WS_EX_TOPMOST:
                        # Ignore windows of class 'Button' (the Start button overlay) and
                        # 'Shell_TrayWnd' (the Task Bar).
                        className = win32gui.GetClassName(hwnd)
                        if not (className == 'Button' or className == 'Shell_TrayWnd'):
                            # Force-minimize the window.
                            # Fortunately, this seems to work even with windows that
                            # have no Minimize button.
                            # Note that if we tried to hide the window with SW_HIDE,
                            # it would disappear from the Task Bar as well.
                            win32gui.ShowWindow(hwnd, win32con.SW_FORCEMINIMIZE)
    
    
        if __name__ == '__main__':
            # regex = ".*11i.*Internet Explorer.*"
            regex = ".*百度.*"
            cW = cWindow()
            cW.find_window_regex(regex)
            cW.Maximize()
            cW.SetAsForegroundWindow()
  • 相关阅读:
    scikit_learn 官方文档翻译(集成学习)
    机器学习之SVM与逻辑回归的联系和区别
    有序数组寻找中位数以及寻找K大元素
    有向图算法之拓扑排序
    机器学习之离散型特征处理--独热码(one_hot_encoding)
    计算广告学(2)--广告有效性模型
    机器学习实战--k-均值聚类
    SonarQube 扫描代码,SonarQube 进行代码质量检查
    Docker 搭建 Nexus3
    informix 安装 linux 客户端
  • 原文地址:https://www.cnblogs.com/lnd-blog/p/14244834.html
Copyright © 2011-2022 走看看