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

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

项目: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
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def OnInitDialog(self, hwnd, msg, wparam, lparam):
        self.hwnd = hwnd

        desktop = win32gui.GetDesktopWindow()
        dt_l, dt_t, dt_r, dt_b = win32gui.GetWindowRect(desktop)
        centre_x, centre_y = win32gui.ClientToScreen( desktop, ( (dt_r-dt_l)/2, (dt_b-dt_t)/2) )

        bmCtrl = win32gui.GetDlgItem(self.hwnd, IDC_BITMAP)
        win32gui.SendMessage(bmCtrl, win32con.STM_SETIMAGE, win32con.IMAGE_BITMAP, self.hSplash)

        win32gui.SetWindowPos(self.hwnd, win32con.HWND_TOPMOST, 
                              centre_x-(self.bmWidth/2), centre_y-(self.bmHeight/2), 
                              self.bmWidth, self.bmHeight, win32con.SWP_HIDEWINDOW)
        win32gui.SetForegroundWindow(self.hwnd)
项目: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)
项目:Comictagger    作者:dickloraine    | 项目源码 | 文件源码
def bringToTop(self):
        if platform.system() == "Windows":
            self.showNormal()
            self.raise_()
            self.activateWindow()
            try:
                import win32con
                import win32gui
                hwnd = self.effectiveWinId()
                rect = win32gui.GetWindowRect(hwnd)
                x = rect[0]
                y = rect[1]
                w = rect[2] - x
                h = rect[3] - y
                # mark it "always on top", just for a moment, to force it to the top
                win32gui.SetWindowPos(hwnd,win32con.HWND_TOPMOST,   x, y, w, h, 0)
                win32gui.SetWindowPos(hwnd,win32con.HWND_NOTOPMOST, x, y, w, h, 0)
            except Exception as e:
                print "Whoops", e
        elif platform.system() == "Darwin":
            self.raise_()
            self.showNormal()
            self.activateWindow()
        else:
            flags = self.windowFlags() 
            self.setWindowFlags( flags |  QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.X11BypassWindowManagerHint)
            QtCore.QCoreApplication.processEvents()
            #self.show()
            self.setWindowFlags( flags )
            self.show()
项目: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()
项目:FindColor    作者:JarenChow    | 项目源码 | 文件源码
def set_window_top():
    hwnd = win32gui.GetForegroundWindow()
    (left, top, right, bottom) = win32gui.GetWindowRect(hwnd)
    win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, left, top, right - left, bottom - top, 0)
项目: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);
项目:InstaGoogling    作者:Ivanca    | 项目源码 | 文件源码
def set_always_on_top(val):
    global windowsWindow
    global isOnTop

    if isWindows:
        if windowsWindow:
            rect = win32gui.GetWindowRect(windowsWindow)
            x = rect[0]
            y = rect[1]
            w = rect[2] - x
            h = rect[3] - y
            placement = win32gui.GetWindowPlacement(windowsWindow)
            if val is True:
                win32gui.SetWindowPos(windowsWindow, win32con.HWND_TOPMOST, x, y, w, h, placement[1])
                isOnTop = True
                # win32gui.SetFocus(windowsWindow)
            else:
                win32gui.SetWindowPos(windowsWindow, win32con.HWND_NOTOPMOST, x, y, w, h, placement[1])
                isOnTop = False
            return True
        else:
            print("Window with title 'Google It Up!' doesnt exist")
            return False

    elif isMac:
        # Not working, dont try
        command = "/usr/bin/osascript -e 'tell app \"System Events\"' " 
        command += "-e 'set theApps to every process whose name contains \"Google It Up!\"' "
        command += "-e 'set theApp to item 1 of theApps' -e 'set frontmost of theApp to true' "
        command += "-e 'end tell'"
        if val == False:
            command = command.replace('true', 'false')
        os.system(command)
项目:PyUIA    作者:xiaoxiayu    | 项目源码 | 文件源码
def FX_ShowWindow(Win32Window):
    win32gui.SetForegroundWindow(Win32Window) 
    win32gui.SetWindowPos(Win32Window, \
                          win32con.HWND_TOP, \
                          0,0,0,0, \
                          win32con.SWP_SHOWWINDOW)
项目:PyUIA    作者:xiaoxiayu    | 项目源码 | 文件源码
def FX_ShowWindowMax(Win32Window):
    win32gui.SetForegroundWindow(Win32Window) 
##    win32gui.SetWindowPos(Win32Window, \
##                          win32con.HWND_TOP, \
##                          0,0,0,0, \
##                          win32con.SWP_SHOWWINDOW)
    win32gui.ShowWindow(Win32Window, win32con.SW_MAXIMIZE)
项目:Automation-Framework-for-devices    作者:tok-gogogo    | 项目源码 | 文件源码
def op_web(self,total=4):
        run_total = 0
        while True:
            run_total = run_total + 1
            print 'run_total:',run_total
            app_f = findwindows.find_windows(class_name_re = "MainForm")
            print 'app_f:',app_f
            self.driver = webdriver.Firefox()
            try:
                for hwnd in app_f:
                    win32gui.MoveWindow(hwnd,0,0,1228,664,1)
                    win32gui.MoveWindow(hwnd,20,20,1248,684,1)
                    win32gui.SetWindowPos(hwnd,win32con.HWND_TOP,0,0,1228,664,win32con.HWND_TOP|win32con.SWP_SHOWWINDOW)
                    break
                self.driver.delete_all_cookies()
                self.driver.get(self.base_url)


                time.sleep(20)
                js="var q=document.documentElement.scrollTop=1500"
                self.driver.execute_script(js)
                self.main_win = self.driver.current_window_handle

                self.tmp_list=[]
                num_l = self.tmp_list_num(BABY_TOTAL)
                random.shuffle(num_l)
                self.tmp_list.append(self.main_win)
                tmpnum = 0
                while True:
                    num = random.randrange(0,len(num_l)-1)
                    tmpnum = num_l[num]
                    del num_l[num]
                    print 'num:',num ,'  tmpnum:',tmpnum
                    self.caozuo(self.driver,str(tmpnum))
                    self.driver.switch_to_window(self.main_win)
                    tmpnum = tmpnum +1
                    if tmpnum >total:
                        break
                self.driver.quit()

            except Exception,e:
                print 'except:',e
                time.sleep(60)
                self.driver.quit()
                pass
            time.sleep(20)