當前位置: 首頁>>代碼示例>>Python>>正文


Python win32gui.GetWindowRect方法代碼示例

本文整理匯總了Python中win32gui.GetWindowRect方法的典型用法代碼示例。如果您正苦於以下問題:Python win32gui.GetWindowRect方法的具體用法?Python win32gui.GetWindowRect怎麽用?Python win32gui.GetWindowRect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在win32gui的用法示例。


在下文中一共展示了win32gui.GetWindowRect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: GetWindowState

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def GetWindowState(self):
        hWnd = Find_MPC()
        if not hWnd:
            return -1
        else:
            hWnd = hWnd[0]
        if not IsWindowVisible(hWnd):
            return 0
        state = GetWindowPlacement(hWnd)[1]
        border = GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_WINDOWEDGE
        if border:
            return state
        rect = GetWindowRect(hWnd)
        mons = EnumDisplayMonitors()
        fullscreen = False
        for mon in mons:
            if rect == mon[2]:
                fullscreen = True
                break
        if fullscreen:
            return 4
        return state
#=============================================================================== 
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:25,代碼來源:__init__.py

示例2: _DoSize

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def _DoSize(self, cx, cy, repaint = 1):
        # right-justify the textbox.
        ctrl = win32gui.GetDlgItem(self.hwnd, IDC_SEARCHTEXT)
        l, t, r, b = win32gui.GetWindowRect(ctrl)
        l, t = win32gui.ScreenToClient(self.hwnd, (l,t) )
        r, b = win32gui.ScreenToClient(self.hwnd, (r,b) )
        win32gui.MoveWindow(ctrl, l, t, cx-l-5, b-t, repaint)
        # The button.
        ctrl = win32gui.GetDlgItem(self.hwnd, IDC_BUTTON_DISPLAY)
        l, t, r, b = win32gui.GetWindowRect(ctrl)
        l, t = win32gui.ScreenToClient(self.hwnd, (l,t) )
        r, b = win32gui.ScreenToClient(self.hwnd, (r,b) )
        list_y = b + 10
        w = r - l
        win32gui.MoveWindow(ctrl, cx - 5 - w, t, w, b-t, repaint)

        # The list control
        win32gui.MoveWindow(self.hwndList, 0, list_y, cx, cy-list_y, repaint)
        # The last column of the list control.
        new_width = cx - win32gui.SendMessage(self.hwndList, commctrl.LVM_GETCOLUMNWIDTH, 0)
        win32gui.SendMessage(self.hwndList, commctrl.LVM_SETCOLUMNWIDTH, 1, new_width) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:23,代碼來源:win32gui_dialog.py

示例3: find_window_movetop

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
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 
開發者ID:Sunuba,項目名稱:roc,代碼行數:9,代碼來源:Clicker.py

示例4: __init__

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def __init__(self, hwnd, quit_game_enable=1):
        '''
        初始化
            :param hwnd: 需要綁定的窗口句柄
            :param quit_game_enable: 程序死掉時是否退出遊戲。True為是,False為否
        '''
        self.run = True
        self.hwnd = hwnd
        self.quit_game_enable = quit_game_enable
        self.debug_enable = False
        l1, t1, r1, b1 = win32gui.GetWindowRect(self.hwnd)
        #print(l1,t1, r1,b1)
        l2, t2, r2, b2 = win32gui.GetClientRect(self.hwnd)
        # print(l2,t2,r2,b2)
        self._client_h = b2 - t2
        self._client_w = r2 - l2
        self._border_l = ((r1 - l1) - (r2 - l2)) // 2
        self._border_t = ((b1 - t1) - (b2 - t2)) - self._border_l
        conf = configparser.ConfigParser()
        conf.read('conf.ini')
        self.client = conf.getint('DEFAULT', 'client')
        if self.client == 1:
            os.system('adb connect 127.0.0.1:7555')
            os.system('adb devices') 
開發者ID:AcademicDog,項目名稱:onmyoji_bot,代碼行數:26,代碼來源:game_ctl.py

示例5: _DoSize

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def _DoSize(self, cx, cy, repaint=1):
        # right-justify the textbox.
        # ctrl = win32gui.GetDlgItem(self.hwnd, IDC_JOB_NAME)
        # win32gui.SetWindowText(ctrl, self.job_name)
        # l, t, r, b = win32gui.GetWindowRect(ctrl)
        # l, t = win32gui.ScreenToClient(self.hwnd, (l, t))
        # r, b = win32gui.ScreenToClient(self.hwnd, (r, b))
        # win32gui.MoveWindow(ctrl, l, t, cx-l-5, b-t, repaint)

        ctrl = win32gui.GetDlgItem(self.hwnd, IDC_SCRIPT)
        win32gui.SetFocus(ctrl)

        # The button.
        ctrl = win32gui.GetDlgItem(self.hwnd, IDC_BUTTON_SUBMIT)
        l, t, r, b = win32gui.GetWindowRect(ctrl)
        l, t = win32gui.ScreenToClient(self.hwnd, (l, t))
        r, b = win32gui.ScreenToClient(self.hwnd, (r, b))
        w = r - l
        win32gui.MoveWindow(ctrl, cx - 5 - w, t, w, b - t, repaint) 
開發者ID:eavatar,項目名稱:eavatar-me,代碼行數:21,代碼來源:console.py

示例6: _DoSize

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def _DoSize(self, cx, cy, repaint=1):
        # right-justify the textbox.
        # ctrl = win32gui.GetDlgItem(self.hwnd, IDC_JOB_NAME)
        # win32gui.SetWindowText(ctrl, self.job_name)
        # l, t, r, b = win32gui.GetWindowRect(ctrl)
        # l, t = win32gui.ScreenToClient(self.hwnd, (l, t))
        # r, b = win32gui.ScreenToClient(self.hwnd, (r, b))
        # win32gui.MoveWindow(ctrl, l, t, cx-l-5, b-t, repaint)

        ctrl = win32gui.GetDlgItem(self.hwnd, IDC_SCRIPT)
        win32gui.SetFocus(ctrl)

        # The button.
        ctrl = win32gui.GetDlgItem(self.hwnd, IDC_BUTTON_SUBMIT)
        l, t, r, b = win32gui.GetWindowRect(ctrl)
        l, t = win32gui.ScreenToClient(self.hwnd, (l, t))
        r, b = win32gui.ScreenToClient(self.hwnd, (r, b))
        w = r - l
        win32gui.MoveWindow(ctrl, cx - 5 - w, t, w, b-t, repaint) 
開發者ID:eavatar,項目名稱:eavatar-me,代碼行數:21,代碼來源:notice_dlg.py

示例7: winRect

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def winRect(window_id :int) -> Tuple[int, int, int, int]:
        """Returns the coordinates of the window"""
        return win32gui.GetWindowRect(window_id) 
開發者ID:kujan,項目名稱:NGU-scripts,代碼行數:5,代碼來源:window.py

示例8: get_bitmap

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def get_bitmap() -> image:
        """Get and return a bitmap of the Window."""
        left, top, right, bot = win32gui.GetWindowRect(Window.id)
        w = right - left
        h = bot - top
        hwnd_dc = win32gui.GetWindowDC(Window.id)
        mfc_dc = win32ui.CreateDCFromHandle(hwnd_dc)
        save_dc = mfc_dc.CreateCompatibleDC()
        save_bitmap = win32ui.CreateBitmap()
        save_bitmap.CreateCompatibleBitmap(mfc_dc, w, h)
        save_dc.SelectObject(save_bitmap)
        windll.user32.PrintWindow(Window.id, save_dc.GetSafeHdc(), 0)
        bmpinfo = save_bitmap.GetInfo()
        bmpstr = save_bitmap.GetBitmapBits(True)

        # This creates an Image object from Pillow
        bmp = image.frombuffer('RGB',
                               (bmpinfo['bmWidth'],
                                bmpinfo['bmHeight']),
                               bmpstr, 'raw', 'BGRX', 0, 1)

        win32gui.DeleteObject(save_bitmap.GetHandle())
        save_dc.DeleteDC()
        mfc_dc.DeleteDC()
        win32gui.ReleaseDC(Window.id, hwnd_dc)
        # bmp.save("asdf.png")
        return bmp 
開發者ID:kujan,項目名稱:NGU-scripts,代碼行數:29,代碼來源:inputs.py

示例9: GetHWND

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
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 
開發者ID:nicholastoddsmith,項目名稱:poeai,代碼行數:17,代碼來源:ScreenViewer.py

示例10: GetScreenImg

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def GetScreenImg(self):
        '''
        Gets the screen of the window referenced by self.hwnd
        '''
        if self.hwnd is None:
            raise Exception("HWND is none. HWND not called or invalid window name provided.")
        self.l, self.t, self.r, self.b = win32gui.GetWindowRect(self.hwnd)
        #Remove border around window (8 pixels on each side)
        #Remove 4 extra pixels from left and right 16 + 8 = 24
        w = self.r - self.l - self.br - self.bl
        #Remove border on top and bottom (31 on top 8 on bottom)
        #Remove 12 extra pixels from bottom 39 + 12 = 51
        h = self.b - self.t - self.bt - self.bb
        wDC = win32gui.GetWindowDC(self.hwnd)
        dcObj = win32ui.CreateDCFromHandle(wDC)
        cDC = dcObj.CreateCompatibleDC()
        dataBitMap = win32ui.CreateBitmap()
        dataBitMap.CreateCompatibleBitmap(dcObj, w, h)
        cDC.SelectObject(dataBitMap)
        #First 2 tuples are top-left and bottom-right of destination
        #Third tuple is the start position in source
        cDC.BitBlt((0,0), (w, h), dcObj, (self.bl, self.bt), win32con.SRCCOPY)
        bmInfo = dataBitMap.GetInfo()
        im = np.frombuffer(dataBitMap.GetBitmapBits(True), dtype = np.uint8)
        dcObj.DeleteDC()
        cDC.DeleteDC()
        win32gui.ReleaseDC(self.hwnd, wDC)
        win32gui.DeleteObject(dataBitMap.GetHandle())
        #Bitmap has 4 channels like: BGRA. Discard Alpha and flip order to RGB
        #31 pixels from border on top, 8 on bottom
        #8 pixels from border on the left and 8 on right
        #Remove 1 additional pixel from left and right so size is 1278 | 9
        #Remove 14 additional pixels from bottom so size is 786 | 6
        #return im.reshape(bmInfo['bmHeight'], bmInfo['bmWidth'], 4)[31:-22, 9:-9, -2::-1]
        #For 800x600 images:
        #Remove 12 pixels from bottom + border
        #Remove 4 pixels from left and right + border
        return im.reshape(bmInfo['bmHeight'], bmInfo['bmWidth'], 4)[:, :, -2::-1] 
開發者ID:nicholastoddsmith,項目名稱:poeai,代碼行數:40,代碼來源:ScreenViewer.py

示例11: OnInitDialog

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def OnInitDialog(self, hwnd, msg, wparam, lparam):
        self.hwnd = hwnd
        # centre the dialog
        desktop = win32gui.GetDesktopWindow()
        l,t,r,b = win32gui.GetWindowRect(self.hwnd)
        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) )
        win32gui.MoveWindow(hwnd, centre_x-(r//2), centre_y-(b//2), r-l, b-t, 0)
        self._SetupList()
        l,t,r,b = win32gui.GetClientRect(self.hwnd)
        self._DoSize(r-l,b-t, 1) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:win32gui_dialog.py

示例12: OnInitDialog

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def OnInitDialog(self, hwnd, msg, wparam, lparam):
        self.hwnd = hwnd
        # centre the dialog
        desktop = win32gui.GetDesktopWindow()
        l,t,r,b = win32gui.GetWindowRect(self.hwnd)
        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) )
        win32gui.MoveWindow(hwnd, centre_x-(r//2), centre_y-(b//2), r-l, b-t, 0) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:win32rcparser_demo.py

示例13: __init__

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def __init__(self):
        self.hwnd = FindWindow(None, "掃雷")  # 獲取掃雷遊戲窗口的句柄
        assert self.hwnd, "請先打開掃雷,再運行該腳本程序"
        SendMessage(self.hwnd, WM_SYSCOMMAND, SC_RESTORE, 0)  # 還原最小化
        SetForegroundWindow(self.hwnd)  # 窗口置頂

        self.pixel_size = 16  # 每個格子的大小固定,為16個像素
        self.left, self.top, self.right, self.bottom = GetWindowRect(self.hwnd)  # 獲取窗口坐標
        self.rank = None  # 掃雷遊戲的等級,分為:高級、中級、初級,不包含自定義模式
        self.max_mines = 0  # 掃雷遊戲的所有雷的數目

        # 去除窗口邊框,隻保留所有格子
        self.left = self.left + 15  # 左邊框15個像素寬
        self.right = self.right - 11  # 右邊框11個像素寬
        self.bottom = self.bottom - 11  # 下邊框11個像素寬
        self.top = self.top + 101  # 尚邊框101個像素寬

        # 獲得遊戲橫向和縱向的格子數目
        self.height = int((self.bottom - self.top) / self.pixel_size)  # 掃雷遊戲的縱向格子數目
        assert self.height in [16, 16, 9]
        self.length = int((self.right - self.left) / self.pixel_size)  # 掃雷遊戲的橫向格子數目
        assert self.length in [30, 16, 9]

        # 獲取遊戲難度級別
        self.get_rank()
        self.get_max_mines() 
開發者ID:buaazyc,項目名稱:Automatic-minesweeping,代碼行數:28,代碼來源:window.py

示例14: get_rect

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def get_rect(self):
        """
        Get rectangle of app or desktop resolution

        Returns:
            RECT(left, top, right, bottom)

        """
        if self.handle:
            left, top, right, bottom = win32gui.GetWindowRect(self.handle)
            return RECT(left, top, right, bottom)
        else:
            desktop = win32gui.GetDesktopWindow()
            left, top, right, bottom = win32gui.GetWindowRect(desktop)
            return RECT(left, top, right, bottom) 
開發者ID:AirtestProject,項目名稱:Airtest,代碼行數:17,代碼來源:win_ide.py

示例15: shot

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowRect [as 別名]
def shot(cls,name= 'playing.png'):
        hwnd = win32gui.FindWindow(None, cls.processname)

        # Change the line below depending on whether you want the whole window
        # or just the client area. 
        left, top, right, bot = win32gui.GetClientRect(hwnd)
        #left, top, right, bot = win32gui.GetWindowRect(hwnd)
        w = right - left
        h = bot - top

        hwndDC = win32gui.GetWindowDC(hwnd)
        mfcDC  = win32ui.CreateDCFromHandle(hwndDC)
        saveDC = mfcDC.CreateCompatibleDC()

        saveBitMap = win32ui.CreateBitmap()
        saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)

        saveDC.SelectObject(saveBitMap)

        # Change the line below depending on whether you want the whole window
        # or just the client area. 
        #result = windll.user32.PrintWindow(hwnd, saveDC.GetSafeHdc(), 1)
        result = windll.user32.PrintWindow(hwnd, saveDC.GetSafeHdc(), 0)

        bmpinfo = saveBitMap.GetInfo()
        bmpstr = saveBitMap.GetBitmapBits(True)

        im = Image.frombuffer(
            'RGB',
            (bmpinfo['bmWidth'], bmpinfo['bmHeight']),
            bmpstr, 'raw', 'BGRX', 0, 1)

        win32gui.DeleteObject(saveBitMap.GetHandle())
        saveDC.DeleteDC()
        mfcDC.DeleteDC()
        win32gui.ReleaseDC(hwnd, hwndDC)

        if result == 1:
            #PrintWindow Succeeded
            im.save("playing.png") 
開發者ID:Sunuba,項目名稱:roc,代碼行數:42,代碼來源:Screenshot.py


注:本文中的win32gui.GetWindowRect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。