Python win32con 模块,SWP_NOSIZE 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用win32con.SWP_NOSIZE

项目:django-runner    作者:awecode    | 项目源码 | 文件源码
def show_window(self):
        self.load()
        try:
            from win32gui import SetWindowPos
            import win32con

            SetWindowPos(self.winId(),
                         win32con.HWND_TOPMOST,
                         # = always on top. only reliable way to bring it to the front on windows
                         0, 0, 0, 0,
                         win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
            SetWindowPos(self.winId(),
                         win32con.HWND_NOTOPMOST,  # disable the always on top, but leave window at its top position
                         0, 0, 0, 0,
                         win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
        except ImportError:
            pass

        self.raise_()
        self.showMaximized()
        self.setWindowState(self.windowState() & ~Qt.WindowMinimized | Qt.WindowActive)
        self.activateWindow()
项目:audio-visualizer-screenlet    作者:ninlith    | 项目源码 | 文件源码
def stay_on_bottom(self):
        """Pin to desktop or something close enough (call repeatedly)."""
        if self.is_desktop_on_foreground():
            if self.topmost is False:
                win32gui.SetWindowPos(
                    self.hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0,
                    win32con.SWP_NOSIZE | win32con.SWP_NOMOVE)
                self.topmost = True
        else:
            if self.topmost is True:
                win32gui.SetWindowPos(
                    self.hwnd, win32con.HWND_BOTTOM, 0, 0, 0, 0,
                    win32con.SWP_NOSIZE | win32con.SWP_NOMOVE)
                self.topmost = False

    # "To prevent the window button from being placed on the taskbar, create
    # the unowned window with the WS_EX_TOOLWINDOW extended style. As an
    # alternative, you can create a hidden window and make this hidden window
    # the owner of your visible window. The Shell will remove a window's button
    # from the taskbar only if the window's style supports visible taskbar
    # buttons. If you want to dynamically change a window's style to one that
    # doesn't support visible taskbar buttons, you must hide the window first
    # (by calling ShowWindow with SW_HIDE), change the window style, and then
    # show the window."
    # -- https://msdn.microsoft.com/en-us/library/bb776822%28v=vs.85%29.aspx
项目:LoLVRSpectate    作者:Fire-Proof    | 项目源码 | 文件源码
def window_foreground_loop(timeout=20):
    """ set the windows python console to the foreground (for example when you are working with a fullscreen program) """
    hwnd=int(win32console.GetConsoleWindow())
    while True:
        win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0,0,0,0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
        time.sleep(timeout)
项目:autoops_for_win    作者:qiueer    | 项目源码 | 文件源码
def SetWinCenter(cls, whd):
        rect = WinUtil.GetCompRect(whd)
        left = (win32api.GetSystemMetrics(win32con.SM_CXFULLSCREEN)-(rect.right-rect.left))/2;  
        top = (win32api.GetSystemMetrics(win32con.SM_CYFULLSCREEN)-(rect.bottom-rect.top))/2;  
        #Move the window to the correct coordinates with SetWindowPos()  
        cls.SetAsForegroundWindow(whd)
        win32gui.SetWindowPos(whd, win32con.HWND_TOPMOST, left, top,-1,-1, win32con.SWP_NOSIZE | win32con.SWP_NOZORDER);  
        win32gui.SetWindowPos(whd, win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_NOSIZE | win32con.SWP_NOMOVE);
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def CalcDynamicLayout(self, length, mode):
        # Support for diagonal sizing.
        if self.IsFloating():
            self.GetParent().GetParent().ModifyStyle(win32ui.MFS_4THICKFRAME, 0)
        if mode & (win32ui.LM_HORZDOCK | win32ui.LM_VERTDOCK):
            flags = win32con.SWP_NOSIZE | win32con.SWP_NOMOVE | win32con.SWP_NOZORDER |\
                win32con.SWP_NOACTIVATE | win32con.SWP_FRAMECHANGED
            self.SetWindowPos(0, (0, 0, 0, 0,), flags)
            self.dockSite.RecalcLayout()
            return self._obj_.CalcDynamicLayout(length, mode)

        if mode & win32ui.LM_MRUWIDTH:
            return self.sizeFloat
        if mode & win32ui.LM_COMMIT:
            self.sizeFloat = length, self.sizeFloat[1]
            return self.sizeFloat
        # More diagonal sizing.
        if self.IsFloating():
            dc = self.dockContext
            pt = win32api.GetCursorPos()
            windowRect = self.GetParent().GetParent().GetWindowRect()

            hittest = dc.nHitTest
            if hittest==win32con.HTTOPLEFT:
                cx = max(windowRect[2] - pt[0], self.cMinWidth) - self.cxBorder
                cy = max(windowRect[3] - self.cCaptionSize - pt[1],self.cMinHeight) - 1
                self.sizeFloat = cx, cy

                top = min(pt[1], windowRect[3] - self.cCaptionSize - self.cMinHeight) - self.cyBorder
                left = min(pt[0], windowRect[2] - self.cMinWidth) - 1
                dc.rectFrameDragHorz = left, top, dc.rectFrameDragHorz[2], dc.rectFrameDragHorz[3]
                return self.sizeFloat
            if hittest==win32con.HTTOPRIGHT:
                cx = max(pt[0] - windowRect[0], self.cMinWidth)
                cy = max(windowRect[3] - self.cCaptionSize - pt[1], self.cMinHeight) - 1
                self.sizeFloat = cx, cy

                top = min(pt[1], windowRect[3] - self.cCaptionSize - self.cMinHeight) - self.cyBorder
                dc.rectFrameDragHorz = dc.rectFrameDragHorz[0], top, dc.rectFrameDragHorz[2], dc.rectFrameDragHorz[3]
                return self.sizeFloat

            if hittest==win32con.HTBOTTOMLEFT:
                cx = max(windowRect[2] - pt[0], self.cMinWidth) - self.cxBorder
                cy = max(pt[1] - windowRect[1] - self.cCaptionSize, self.cMinHeight)
                self.sizeFloat = cx, cy

                left = min(pt[0], windowRect[2] -self.cMinWidth) - 1
                dc.rectFrameDragHorz = left, dc.rectFrameDragHorz[1], dc.rectFrameDragHorz[2], dc.rectFrameDragHorz[3]
                return self.sizeFloat

            if hittest==win32con.HTBOTTOMRIGHT:
                cx = max(pt[0] - windowRect[0], self.cMinWidth)
                cy = max(pt[1] - windowRect[1] - self.cCaptionSize, self.cMinHeight)
                self.sizeFloat = cx, cy
                return self.sizeFloat

        if mode & win32ui.LM_LENGTHY:
            self.sizeFloat = self.sizeFloat[0], max(self.sizeMin[1], length)
            return self.sizeFloat
        else:
            return max(self.sizeMin[0], length), self.sizeFloat[1]
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def OnWindowPosChanged(self, msg):
        if self.GetSafeHwnd()==0 or self.dialog is None:
            return 0
        lparam = msg[3]
        """ LPARAM used with WM_WINDOWPOSCHANGED:
            typedef struct {
                HWND hwnd;
                HWND hwndInsertAfter;
                int x;
                int y;
                int cx;
                int cy;
                UINT flags;} WINDOWPOS;
        """
        format = "PPiiiii"
        bytes = win32ui.GetBytes( lparam, struct.calcsize(format) )
        hwnd, hwndAfter, x, y, cx, cy, flags = struct.unpack(format, bytes)

        if self.bInRecalcNC:
            rc = self.GetClientRect()
            self.dialog.MoveWindow(rc)
            return 0
        # Find on which side are we docked
        nDockBarID = self.GetParent().GetDlgCtrlID()
        # Return if dropped at same location
        # no docking side change and no size change
        if (nDockBarID == self.nDockBarID) and \
            (flags & win32con.SWP_NOSIZE) and \
            ((self._obj_.dwStyle & afxres.CBRS_BORDER_ANY) != afxres.CBRS_BORDER_ANY):
            return
        self.nDockBarID = nDockBarID

        # Force recalc the non-client area
        self.bInRecalcNC = 1
        try:
            swpflags = win32con.SWP_NOSIZE | win32con.SWP_NOMOVE | win32con.SWP_NOZORDER | win32con.SWP_FRAMECHANGED
            self.SetWindowPos(0, (0,0,0,0), swpflags)
        finally:
            self.bInRecalcNC = 0
        return 0

    # This is a virtual and not a message hook.
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def CalcDynamicLayout(self, length, mode):
        # Support for diagonal sizing.
        if self.IsFloating():
            self.GetParent().GetParent().ModifyStyle(win32ui.MFS_4THICKFRAME, 0)
        if mode & (win32ui.LM_HORZDOCK | win32ui.LM_VERTDOCK):
            flags = win32con.SWP_NOSIZE | win32con.SWP_NOMOVE | win32con.SWP_NOZORDER |\
                win32con.SWP_NOACTIVATE | win32con.SWP_FRAMECHANGED
            self.SetWindowPos(0, (0, 0, 0, 0,), flags)
            self.dockSite.RecalcLayout()
            return self._obj_.CalcDynamicLayout(length, mode)

        if mode & win32ui.LM_MRUWIDTH:
            return self.sizeFloat
        if mode & win32ui.LM_COMMIT:
            self.sizeFloat = length, self.sizeFloat[1]
            return self.sizeFloat
        # More diagonal sizing.
        if self.IsFloating():
            dc = self.dockContext
            pt = win32api.GetCursorPos()
            windowRect = self.GetParent().GetParent().GetWindowRect()

            hittest = dc.nHitTest
            if hittest==win32con.HTTOPLEFT:
                cx = max(windowRect[2] - pt[0], self.cMinWidth) - self.cxBorder
                cy = max(windowRect[3] - self.cCaptionSize - pt[1],self.cMinHeight) - 1
                self.sizeFloat = cx, cy

                top = min(pt[1], windowRect[3] - self.cCaptionSize - self.cMinHeight) - self.cyBorder
                left = min(pt[0], windowRect[2] - self.cMinWidth) - 1
                dc.rectFrameDragHorz = left, top, dc.rectFrameDragHorz[2], dc.rectFrameDragHorz[3]
                return self.sizeFloat
            if hittest==win32con.HTTOPRIGHT:
                cx = max(pt[0] - windowRect[0], self.cMinWidth)
                cy = max(windowRect[3] - self.cCaptionSize - pt[1], self.cMinHeight) - 1
                self.sizeFloat = cx, cy

                top = min(pt[1], windowRect[3] - self.cCaptionSize - self.cMinHeight) - self.cyBorder
                dc.rectFrameDragHorz = dc.rectFrameDragHorz[0], top, dc.rectFrameDragHorz[2], dc.rectFrameDragHorz[3]
                return self.sizeFloat

            if hittest==win32con.HTBOTTOMLEFT:
                cx = max(windowRect[2] - pt[0], self.cMinWidth) - self.cxBorder
                cy = max(pt[1] - windowRect[1] - self.cCaptionSize, self.cMinHeight)
                self.sizeFloat = cx, cy

                left = min(pt[0], windowRect[2] -self.cMinWidth) - 1
                dc.rectFrameDragHorz = left, dc.rectFrameDragHorz[1], dc.rectFrameDragHorz[2], dc.rectFrameDragHorz[3]
                return self.sizeFloat

            if hittest==win32con.HTBOTTOMRIGHT:
                cx = max(pt[0] - windowRect[0], self.cMinWidth)
                cy = max(pt[1] - windowRect[1] - self.cCaptionSize, self.cMinHeight)
                self.sizeFloat = cx, cy
                return self.sizeFloat

        if mode & win32ui.LM_LENGTHY:
            self.sizeFloat = self.sizeFloat[0], max(self.sizeMin[1], length)
            return self.sizeFloat
        else:
            return max(self.sizeMin[0], length), self.sizeFloat[1]
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def OnWindowPosChanged(self, msg):
        if self.GetSafeHwnd()==0 or self.dialog is None:
            return 0
        lparam = msg[3]
        """ LPARAM used with WM_WINDOWPOSCHANGED:
            typedef struct {
                HWND hwnd;
                HWND hwndInsertAfter;
                int x;
                int y;
                int cx;
                int cy;
                UINT flags;} WINDOWPOS;
        """
        format = "PPiiiii"
        bytes = win32ui.GetBytes( lparam, struct.calcsize(format) )
        hwnd, hwndAfter, x, y, cx, cy, flags = struct.unpack(format, bytes)

        if self.bInRecalcNC:
            rc = self.GetClientRect()
            self.dialog.MoveWindow(rc)
            return 0
        # Find on which side are we docked
        nDockBarID = self.GetParent().GetDlgCtrlID()
        # Return if dropped at same location
        # no docking side change and no size change
        if (nDockBarID == self.nDockBarID) and \
            (flags & win32con.SWP_NOSIZE) and \
            ((self._obj_.dwStyle & afxres.CBRS_BORDER_ANY) != afxres.CBRS_BORDER_ANY):
            return
        self.nDockBarID = nDockBarID

        # Force recalc the non-client area
        self.bInRecalcNC = 1
        try:
            swpflags = win32con.SWP_NOSIZE | win32con.SWP_NOMOVE | win32con.SWP_NOZORDER | win32con.SWP_FRAMECHANGED
            self.SetWindowPos(0, (0,0,0,0), swpflags)
        finally:
            self.bInRecalcNC = 0
        return 0

    # This is a virtual and not a message hook.