Python win32gui.ShowWindow() Examples

The following are 29 code examples of win32gui.ShowWindow(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32gui , or try the search function .
Example #1
Source File: Clicker.py    From roc with MIT License 15 votes vote down vote up
def find_window_movetop(cls):
        hwnd = win32gui.FindWindow(None, cls.processname)
        win32gui.ShowWindow(hwnd,5)
        win32gui.SetForegroundWindow(hwnd)
        rect = win32gui.GetWindowRect(hwnd)
        sleep(0.2)
        return rect 
Example #2
Source File: steam.py    From Yugioh-bot with MIT License 14 votes vote down vote up
def tap(self, x, y):
        if self.run_time.stop:
            return
        x, y = int(x), int(y)
        self.root.debug("Tapping at location ({},{})".format(x, y))
        if self._debug:
            # Helper to debug taps
            input("waiting for confirmation press enter")
        ox, oy = win32api.GetCursorPos()
        curr_window = win32gui.GetForegroundWindow()
        win32gui.ShowWindow(self.win_handle, win32con.SW_RESTORE)
        x, y = int(x), int(y)
        cx, cy = win32gui.ClientToScreen(self.win_handle, (x, y))
        x, y = self.__calculate_absolute_coordinates__(cx, cy)
        win32api.mouse_event(win32con.MOUSEEVENTF_MOVE | win32con.MOUSEEVENTF_ABSOLUTE,
                             x, y, 0, 0)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
        time.sleep(20 / 1000)
        win32api.SetCursorPos((ox, oy))
        win32gui.SetActiveWindow(curr_window) 
Example #3
Source File: win_utils.py    From plex-mpv-shim with MIT License 8 votes vote down vote up
def raise_mpv():
    # This workaround is madness. Apparently SetForegroundWindow
    # won't work randomly, so I have to call ShowWindow twice.
    # Once to hide the window, and again to successfully raise the window.
    try:
        top_windows = []
        fg_win = win32gui.GetForegroundWindow()
        win32gui.EnumWindows(windowEnumerationHandler, top_windows)
        for i in top_windows:
            if " - mpv" in i[1].lower():
                if i[0] != fg_win:
                    win32gui.ShowWindow(i[0], 6) # Minimize
                    win32gui.ShowWindow(i[0], 9) # Un-minimize
                break

    except Exception:
        print("Could not raise MPV.")
        traceback.print_exc() 
Example #4
Source File: main.py    From MouseTracks with GNU General Public License v3.0 7 votes vote down vote up
def bring_to_front(self, new=True):
        """Bring a window into focus.
        Kept the old way just to be on the safe side.
        """
        if new:
            win32gui.ShowWindow(self.hwnd, True)
        else:
            self.restore()
            
        #Sometimes it seems to fail but then work a second time
        try:
            win32gui.SetForegroundWindow(self.hwnd)
        except pywintypes.error:
            time.sleep(0.5)
            win32gui.ShowWindow(self.hwnd, True)
            try:
                win32gui.SetForegroundWindow(self.hwnd)
            except pywintypes.error:
                pass 
Example #5
Source File: winguiauto.py    From pyautotrade_tdx with GNU General Public License v2.0 7 votes vote down vote up
def focusWindow(hwnd):
    '''
    捕捉窗口焦点
    :param hwnd: 窗体句柄
    :return:
    '''
    win32gui.ShowWindow(hwnd, win32con.SW_SHOWMAXIMIZED)
    win32gui.SetForegroundWindow(hwnd) 
Example #6
Source File: console.py    From eavatar-me with Apache License 2.0 6 votes vote down vote up
def hide(self):
        print("hide")
        win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE)
        self.hidden = True 
Example #7
Source File: console.py    From eavatar-me with Apache License 2.0 6 votes vote down vote up
def show(self):
        # print("show")
        if self.hwnd:
            win32gui.ShowWindow(self.hwnd, win32con.SW_NORMAL)
            self.hidden = False
            self.clear_script() 
Example #8
Source File: ietoolbar.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def ShowDW(self, bShow):
        if bShow:
            self.toolbar.ShowWindow(win32con.SW_SHOW)
        else:
            self.toolbar.ShowWindow(win32con.SW_HIDE) 
Example #9
Source File: winapi.py    From gui-o-matic with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_visibility( self, visibility  ):
        state = win32con.SW_SHOW if visibility else win32con.SW_HIDE
        win32gui.ShowWindow( self.window_handle, state )
        win32gui.UpdateWindow( self.window_handle ) 
Example #10
Source File: notice_dlg.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def hide(self):
        print("hide")
        win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE)
        self.hidden = True 
Example #11
Source File: notice_dlg.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def show(self):
        # print("show")
        if self.hwnd:
            win32gui.ShowWindow(self.hwnd, win32con.SW_NORMAL)
            self.hidden = False
            self._clear_script() 
Example #12
Source File: window.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def show(self):
        win32gui.ShowWindow(self.hwnd, win32con.SW_NORMAL) 
Example #13
Source File: winguiauto.py    From pyAutoTrading with GNU General Public License v2.0 5 votes vote down vote up
def focusWindow(hwnd):
    """
    捕捉窗口焦点
    :param hwnd: 窗体句柄
    :return:
    """
    win32gui.ShowWindow(hwnd, win32con.SW_SHOWMAXIMIZED)
    win32gui.SetForegroundWindow(hwnd) 
Example #14
Source File: winguiauto.py    From pyAutoTrading with GNU General Public License v2.0 5 votes vote down vote up
def restoreFocusWindow(hwnd):
    win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)
    win32gui.SetForegroundWindow(hwnd)
    time.sleep(0.2) 
Example #15
Source File: WindowsUI.py    From Poco with Apache License 2.0 5 votes vote down vote up
def SetForeground(self):
        win32gui.ShowWindow(self.root.Handle, win32con.SW_SHOWNORMAL)  # 先把窗口取消最小化
        UIAuto.Win32API.SetForegroundWindow(self.root.Handle)  # 再把窗口设为前台,方便点击和截图
        return True 
Example #16
Source File: EmbedWindow.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def restore(self):
        """归还窗口"""
        # 有bug,归还后窗口没有了WS_VISIBLE样式,不可见
        widget = self.layout().itemAt(3).widget()
        print('restore', widget.hwnd, widget.style, widget.exstyle)
        win32gui.SetParent(widget.hwnd, widget.phwnd)  # 让它返回它的父窗口
        win32gui.SetWindowLong(
            widget.hwnd, win32con.GWL_STYLE, widget.style | win32con.WS_VISIBLE)  # 恢复样式
        win32gui.SetWindowLong(
            widget.hwnd, win32con.GWL_EXSTYLE, widget.exstyle)  # 恢复样式
        win32gui.ShowWindow(
            widget.hwnd, win32con.SW_SHOW)  # 显示窗口
        widget.close()
        self.layout().removeWidget(widget)  # 从布局中移出
        widget.deleteLater() 
Example #17
Source File: main.py    From MouseTracks with GNU General Public License v3.0 5 votes vote down vote up
def hide(self, new=True):
        """Hide a window from the task bar.
        Kept the old way just to be on the safe side.
        """
        if new:
            win32gui.ShowWindow(self.hwnd, False)
        else:
            self.minimise()
            win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE)
            win32gui.SetWindowLong(self.hwnd, win32con.GWL_EXSTYLE,
                                   win32gui.GetWindowLong(self.hwnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_TOOLWINDOW)
            win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW) 
Example #18
Source File: main.py    From MouseTracks with GNU General Public License v3.0 5 votes vote down vote up
def minimise(self):
        """Minimise a window."""
        win32gui.ShowWindow(self.hwnd, win32con.SW_MINIMIZE) 
Example #19
Source File: main.py    From MouseTracks with GNU General Public License v3.0 5 votes vote down vote up
def restore(self):
        """Restore a window from being minimised."""
        win32gui.ShowWindow(self.hwnd, win32con.SW_RESTORE) 
Example #20
Source File: winguiauto.py    From PyAutoTrading with GNU General Public License v2.0 5 votes vote down vote up
def focusWindow(hwnd):
    '''
    捕捉窗口焦点
    :param hwnd: 窗体句柄
    :return:
    '''
    win32gui.ShowWindow(hwnd, win32con.SW_SHOWMAXIMIZED)
    win32gui.SetForegroundWindow(hwnd) 
Example #21
Source File: winguiauto.py    From pyautotrade_tdx with GNU General Public License v2.0 5 votes vote down vote up
def focusWindow(hwnd):
    '''
    捕捉窗口焦点
    :param hwnd: 窗体句柄
    :return:
    '''
    win32gui.ShowWindow(hwnd, win32con.SW_SHOWMAXIMIZED)
    win32gui.SetForegroundWindow(hwnd) 
Example #22
Source File: window.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _win32gui_show_window(state):
        return lambda self: win32gui.ShowWindow(self._handle, state) 
Example #23
Source File: Lo0sR.py    From Lo0sR with MIT License 5 votes vote down vote up
def hide(self):
        window = win32console.GetConsoleWindow()
        win32gui.ShowWindow(window, 0) 
Example #24
Source File: PyLoggy.py    From PyLoggy with GNU General Public License v3.0 5 votes vote down vote up
def Hide():
    import win32console
    import win32gui
    win = win32console.GetConsoleWindow()
    win32gui.ShowWindow(win, 0) 
Example #25
Source File: win32_window.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _win32gui_show_window(state):
        return lambda self: win32gui.ShowWindow(self._handle, state) 
Example #26
Source File: ietoolbar.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def ShowWindow(self,mode):
        win32gui.ShowWindow(self.hwnd,mode) 
Example #27
Source File: mcplatform.py    From GDMC with ISC License 4 votes vote down vote up
def set_state(self, state=NORMAL, size=(-1, -1), pos=(-1, -1), update=True):
        """Set wheter the window is maximized or not, or minimized or full screen.
        If no argument is given, assume the state will be windowed and not maximized.
        If arguments are given, only the first is relevant. The other ones are ignored.

        ** Only maximized and normal states are implemented for now. **

        :state: valid arguments:
        'minimized', MINIMIZED, 0.
        'normal', NORMAL, 1: windowed, not maximized.
        'maximized', MAXIMIZED, 2.
        'fullscreen, FULLSCREEN, 3.

        :size: list, tuple: the new size; if (-1, -1) self.get_size() is used.
               If one element is -1 it is replaced by the corresponding valur from self.get_size().
        :pos: list, tuple: the new position; if (-1, -1), self.get_position is used.
              If one element is -1 it is replaced by the corresponding valur from self.get_position().
        :update: bool: whether to call the internal flush method."""
        if state not in (0, MINIMIZED, 'minimized', 1, NORMAL, 'normal', 2, MAXIMIZED, 'maximized', 3, FULLSCREEN, 'fullscreen'):
            # Raise a value error.
            raise ValueError, "Invalid state argument: %s is not a correct value" % state
        if type(size) not in (list, tuple):
            raise TypeError, "Invalid size argument: %s is not a list or a tuple."
        if type(pos) not in (list, tuple):
            raise TypeError, "Invalid pos argument: %s is not a list or a tuple."

        if state in (1, NORMAL, 'normal'):
            size = list(size)
            sz = self.get_size()
            if size[0] == -1:
                size[0] = sz[0]
            if size[1] == -1:
                size[1] = sz[1]
            pos = list(pos)
            ps = self.get_position()
            if pos[0] == -1:
                pos[0] = ps[0]
            if pos[1] == -1:
                pos[1] = ps[1]
            self.set_mode(size, self.mode)
            self.set_position(pos)
        elif state in (0, MINIMIZED, 'minimized'):
            pass
        elif state in (2, MAXIMIZED, 'maximized'):
            win32gui.ShowWindow(self.base_handler_id, win32con.SW_MAXIMIZE)
        elif state in (3, FULLSCREEN, 'fullscreen'):
            pass 
Example #28
Source File: utils.py    From QuLab with MIT License 4 votes vote down vote up
def _WindowsShutdownBlocker(title='Python script'):
    """
    Block Windows shutdown when you do something important.
    """
    from ctypes import CFUNCTYPE, c_bool, c_uint, c_void_p, c_wchar_p, windll
    import win32con
    import win32gui

    def WndProc(hWnd, message, wParam, lParam):
        if message == win32con.WM_QUERYENDSESSION:
            return False
        else:
            return win32gui.DefWindowProc(hWnd, message, wParam, lParam)

    CALLBACK = CFUNCTYPE(c_bool, c_void_p, c_uint, c_void_p, c_void_p)

    wc = win32gui.WNDCLASS()
    wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW
    wc.lpfnWndProc = CALLBACK(WndProc)
    wc.hbrBackground = win32con.COLOR_WINDOW + 1
    wc.lpszClassName = "block_shutdown_class"
    win32gui.RegisterClass(wc)

    hwnd = win32gui.CreateWindow(wc.lpszClassName, title,
                                 win32con.WS_OVERLAPPEDWINDOW, 50,
                                 50, 100, 100, 0, 0,
                                 win32gui.GetForegroundWindow(), None)

    win32gui.ShowWindow(hwnd, win32con.SW_HIDE)

    windll.user32.ShutdownBlockReasonCreate.argtypes = [c_void_p, c_wchar_p]
    windll.user32.ShutdownBlockReasonCreate.restype = c_bool
    windll.user32.ShutdownBlockReasonCreate(
        hwnd, "Important work in processing, don't shutdown :-(")

    yield

    windll.user32.ShutdownBlockReasonDestroy.argtypes = [c_void_p]
    windll.user32.ShutdownBlockReasonDestroy.restype = c_bool
    windll.user32.ShutdownBlockReasonDestroy(hwnd)
    win32gui.DestroyWindow(hwnd)
    win32gui.UnregisterClass(wc.lpszClassName, None) 
Example #29
Source File: mcplatform.py    From MCEdit-Unified with ISC License 4 votes vote down vote up
def set_state(self, state=NORMAL, size=(-1, -1), pos=(-1, -1), update=True):
        """Set wheter the window is maximized or not, or minimized or full screen.
        If no argument is given, assume the state will be windowed and not maximized.
        If arguments are given, only the first is relevant. The other ones are ignored.

        ** Only maximized and normal states are implemented for now. **

        :state: valid arguments:
        'minimized', MINIMIZED, 0.
        'normal', NORMAL, 1: windowed, not maximized.
        'maximized', MAXIMIZED, 2.
        'fullscreen, FULLSCREEN, 3.

        :size: list, tuple: the new size; if (-1, -1) self.get_size() is used.
               If one element is -1 it is replaced by the corresponding valur from self.get_size().
        :pos: list, tuple: the new position; if (-1, -1), self.get_position is used.
              If one element is -1 it is replaced by the corresponding valur from self.get_position().
        :update: bool: whether to call the internal flush method."""
        if state not in (0, MINIMIZED, 'minimized', 1, NORMAL, 'normal', 2, MAXIMIZED, 'maximized', 3, FULLSCREEN, 'fullscreen'):
            # Raise a value error.
            raise ValueError("Invalid state argument: %s is not a correct value" % state)
        if not isinstance(size, (list, tuple)):
            raise TypeError("Invalid size argument: %s is not a list or a tuple.")
        if not isinstance(pos, (list, tuple)):
            raise TypeError("Invalid pos argument: %s is not a list or a tuple.")

        if state in (1, NORMAL, 'normal'):
            size = list(size)
            sz = self.get_size()
            if size[0] == -1:
                size[0] = sz[0]
            if size[1] == -1:
                size[1] = sz[1]
            pos = list(pos)
            ps = self.get_position()
            if pos[0] == -1:
                pos[0] = ps[0]
            if pos[1] == -1:
                pos[1] = ps[1]
            self.set_mode(size, self.mode)
            self.set_position(pos)
        elif state in (0, MINIMIZED, 'minimized'):
            pass
        elif state in (2, MAXIMIZED, 'maximized'):
            win32gui.ShowWindow(self.base_handler_id, win32con.SW_MAXIMIZE)
        elif state in (3, FULLSCREEN, 'fullscreen'):
            pass