当前位置: 首页>>代码示例>>Python>>正文


Python win32gui.GetDesktopWindow方法代码示例

本文整理汇总了Python中win32gui.GetDesktopWindow方法的典型用法代码示例。如果您正苦于以下问题:Python win32gui.GetDesktopWindow方法的具体用法?Python win32gui.GetDesktopWindow怎么用?Python win32gui.GetDesktopWindow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32gui的用法示例。


在下文中一共展示了win32gui.GetDesktopWindow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: askOpenFolderWin32

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def askOpenFolderWin32(title, initialDir):
    try:
        desktop_pidl = shell.SHGetFolderLocation(0, shellcon.CSIDL_DESKTOP, 0, 0)
        pidl, display_name, image_list = shell.SHBrowseForFolder (
                                                              win32gui.GetDesktopWindow(),
                                                              desktop_pidl,
                                                              "Choose a folder",
                                                              0,
                                                              None,
                                                              None
                                                              )
        return shell.SHGetPathFromIDList(pidl)
    except pywintypes.com_error as e:
        if e.args[0] == -2147467259:
            print "Invalid folder selected"
        pass 
开发者ID:mcgreentn,项目名称:GDMC,代码行数:18,代码来源:mcplatform.py

示例2: paintEvent

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def paintEvent(self, event):
        super(Label, self).paintEvent(event)
        # 中正间画十字
        painter = QPainter(self)
        painter.setPen(Qt.red)
        x = int(self.width() / 2)
        y = int(self.height() / 2)
        painter.drawLine(x, 0, x, self.height())
        painter.drawLine(0, y, self.width(), y)
        if self.ismd:
            # 画坐标点
            pos = QCursor.pos()
            ret = win32gui.GetPixel(win32gui.GetWindowDC(
                win32gui.GetDesktopWindow()), pos.x(), pos.y())
            r, g, b = ret & 0xff, (ret >> 8) & 0xff, (ret >> 16) & 0xff
            print(r, g, b)
            painter.setPen(Qt.white)
            painter.drawText(self.rect(), Qt.AlignLeft |
                             Qt.AlignBottom, '({}, {})\nRGB: ({}, {}, {})\n{}'.format(
                                 pos.x(), pos.y(), r, g, b, QColor(r, g, b).name())) 
开发者ID:PyQt5,项目名称:PyQt,代码行数:22,代码来源:ProbeWindow.py

示例3: chooseOpenFolder

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def chooseOpenFolder():
    """
    Open a dialog for user to choose a folder/directory.

    :return: the path to the folder, or None if not selected.
    """

    pidl, display_name, image_list = shell.SHBrowseForFolder(
        win32gui.GetDesktopWindow(),
        desktop_pidl,
        "Choose a folder",
        0,
        None,
        None
    )

    if pidl is None:
        return None

    return shell.SHGetPathFromIDList(pidl)


# Test code 
开发者ID:eavatar,项目名称:eavatar-me,代码行数:25,代码来源:simpledialog.py

示例4: GetHWND

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [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

示例5: OnInitDialog

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [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

示例6: OnInitDialog

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [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

示例7: grab_screen

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def grab_screen(region=None):

    hwin = win32gui.GetDesktopWindow()

    if region:
            left,top,x2,y2 = region
            width = x2 - left + 1
            height = y2 - top + 1
    else:
        width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
        height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
        left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
        top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)

    hwindc = win32gui.GetWindowDC(hwin)
    srcdc = win32ui.CreateDCFromHandle(hwindc)
    memdc = srcdc.CreateCompatibleDC()
    bmp = win32ui.CreateBitmap()
    bmp.CreateCompatibleBitmap(srcdc, width, height)
    memdc.SelectObject(bmp)
    memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)
    
    signedIntsArray = bmp.GetBitmapBits(True)
    img = np.fromstring(signedIntsArray, dtype='uint8')
    img.shape = (height,width,4)

    srcdc.DeleteDC()
    memdc.DeleteDC()
    win32gui.ReleaseDC(hwin, hwindc)
    win32gui.DeleteObject(bmp.GetHandle())

    return cv2.cvtColor(img, cv2.COLOR_BGRA2RGB) 
开发者ID:Sentdex,项目名称:pygta5,代码行数:34,代码来源:grabscreen.py

示例8: grab_screen

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def grab_screen(region=None):
    hwin = win32gui.GetDesktopWindow()
    if region:
            left,top,x2,y2 = region
            width = x2 - left + 1
            height = y2 - top + 1
    else:
        width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
        height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
        left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
        top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)

    hwindc = win32gui.GetWindowDC(hwin)
    srcdc = win32ui.CreateDCFromHandle(hwindc)
    memdc = srcdc.CreateCompatibleDC()
    bmp = win32ui.CreateBitmap()
    bmp.CreateCompatibleBitmap(srcdc, width, height)
    memdc.SelectObject(bmp)
    memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)

    signedIntsArray = bmp.GetBitmapBits(True)
    img = np.fromstring(signedIntsArray, dtype='uint8')
    img.shape = (height,width,4)

    srcdc.DeleteDC()
    memdc.DeleteDC()
    win32gui.ReleaseDC(hwin, hwindc)
    win32gui.DeleteObject(bmp.GetHandle())

    return cv2.cvtColor(img, cv2.COLOR_BGRA2RGB) 
开发者ID:Sentdex,项目名称:pygta5,代码行数:32,代码来源:grabscreen.py

示例9: grab_screen

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def grab_screen(region=None):

    hwin = win32gui.GetDesktopWindow()

    if region:
            left,top,x2,y2 = region
            width = x2 - left + 1
            height = y2 - top + 1
    else:
        width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
        height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
        left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
        top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)


    hwindc = win32gui.GetWindowDC(hwin)
    srcdc = win32ui.CreateDCFromHandle(hwindc)
    memdc = srcdc.CreateCompatibleDC()
    bmp = win32ui.CreateBitmap()
    bmp.CreateCompatibleBitmap(srcdc, width, height)
    memdc.SelectObject(bmp)
    memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)
    
    signedIntsArray = bmp.GetBitmapBits(True)
    img = np.fromstring(signedIntsArray, dtype='uint8')
    img.shape = (height,width,4)

    srcdc.DeleteDC()
    memdc.DeleteDC()
    win32gui.ReleaseDC(hwin, hwindc)
    win32gui.DeleteObject(bmp.GetHandle())

    return cv2.cvtColor(img, cv2.COLOR_BGRA2RGB) 
开发者ID:Sentdex,项目名称:pygta5,代码行数:35,代码来源:grabscreen.py

示例10: get_rect

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [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

示例11: get_root_rect

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def get_root_rect(self):
        """Return a four values tuple containing the position and size of the very first OS window object."""
        flags, showCmd, ptMin, ptMax, rect = win32gui.GetWindowPlacement(win32gui.GetDesktopWindow())
        return rect 
开发者ID:mcgreentn,项目名称:GDMC,代码行数:6,代码来源:mcplatform.py

示例12: __init__

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def __init__(self, window_name=None, exe_file=None, exclude_border=True):
        hwnd = 0

        # first check window_name
        if window_name is not None:
            hwnd = win32gui.FindWindow(None, window_name)
            if hwnd == 0:
                def callback(h, extra):
                    if window_name in win32gui.GetWindowText(h):
                        extra.append(h)
                    return True
                extra = []
                win32gui.EnumWindows(callback, extra)
                if extra: hwnd = extra[0]
            if hwnd == 0:
                raise WindowsAppNotFoundError("Windows Application <%s> not found!" % window_name)

        # check exe_file by checking all processes current running.
        elif exe_file is not None:
            pid = find_process_id(exe_file)
            if pid is not None:
                def callback(h, extra):
                    if win32gui.IsWindowVisible(h) and win32gui.IsWindowEnabled(h):
                        _, p = win32process.GetWindowThreadProcessId(h)
                        if p == pid:
                            extra.append(h)
                        return True
                    return True
                extra = []
                win32gui.EnumWindows(callback, extra)
                #TODO: get main window from all windows.
                if extra: hwnd = extra[0]
            if hwnd == 0:
                raise WindowsAppNotFoundError("Windows Application <%s> is not running!" % exe_file)

        # if window_name & exe_file both are None, use the screen.
        if hwnd == 0:
            hwnd = win32gui.GetDesktopWindow()

        self.hwnd = hwnd
        self.exclude_border = exclude_border 
开发者ID:NetEaseGame,项目名称:ATX,代码行数:43,代码来源:windows.py

示例13: __init_screen_handles

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def __init_screen_handles(self):
        # opengl windows cannot get from it's hwnd, so we use the screen
        hwnd = win32gui.GetDesktopWindow()
        # get screen size and offset
        left, top, right, bottom = self.rect
        width, height = right-left, bottom-top
        # the device context of the window 
        hdcwin = win32gui.GetWindowDC(hwnd)
        # make a temporary dc
        hdcmem = win32gui.CreateCompatibleDC(hdcwin)
        # make a temporary bitmap in memory, this is a PyHANDLE object
        hbmp = win32gui.CreateCompatibleBitmap(hdcwin, width, height)
        # select bitmap for temporary dc
        win32gui.SelectObject(hdcmem, hbmp)
        # check the bitmap object infomation
        bmp = win32gui.GetObject(hbmp)
        bi = BITMAPINFOHEADER()
        bi.biSize = ctypes.sizeof(BITMAPINFOHEADER)
        bi.biWidth = bmp.bmWidth
        bi.biHeight = bmp.bmHeight
        bi.biPlanes = bmp.bmPlanes
        bi.biBitCount = bmp.bmBitsPixel
        bi.biCompression = 0 # BI_RGB
        bi.biSizeImage = 0
        bi.biXPelsPerMeter = 0
        bi.biYPelsPerMeter = 0
        bi.biClrUsed = 0
        bi.biClrImportant = 0
        # calculate total size for bits
        pixel = bmp.bmBitsPixel
        size = ((bmp.bmWidth * pixel + pixel - 1)/pixel) * 4 * bmp.bmHeight
        buf = (ctypes.c_char * size)()

        self._hdcwin = hdcwin
        self._hdcmem = hdcmem
        self._bi = bi
        self._hbmp = hbmp
        self._buf = buf 
开发者ID:NetEaseGame,项目名称:ATX,代码行数:40,代码来源:windows.py

示例14: screen

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def screen(self):
        """PIL Image of current window screen.
        reference: https://msdn.microsoft.com/en-us/library/dd183402(v=vs.85).aspx"""
        hwnd = win32gui.GetDesktopWindow()
        left, top, right, bottom = self.rect
        width, height = right-left, bottom-top
        # copy bits to temporary dc
        win32gui.BitBlt(self._hdcmem, 0, 0, width, height, 
                        self._hdcwin, left, top, win32con.SRCCOPY)
        # read bits into buffer
        windll.gdi32.GetDIBits(self._hdcmem, self._hbmp.handle, 0, height, self._buf, ctypes.byref(self._bi), win32con.DIB_RGB_COLORS)
        # make a PIL Image
        img = Image.frombuffer('RGB', (width, height), self._buf, 'raw', 'BGRX', 0, 1)
        img = img.transpose(Image.FLIP_TOP_BOTTOM)
        return img 
开发者ID:NetEaseGame,项目名称:ATX,代码行数:17,代码来源:windows.py

示例15: screen_cv2

# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import GetDesktopWindow [as 别名]
def screen_cv2(self):
        """cv2 Image of current window screen"""
        hwnd = win32gui.GetDesktopWindow()
        left, top, right, bottom = self.rect
        width, height = right-left, bottom-top
        # copy bits to temporary dc
        win32gui.BitBlt(self._hdcmem, 0, 0, width, height, 
                        self._hdcwin, left, top, win32con.SRCCOPY)
        # read bits into buffer
        windll.gdi32.GetDIBits(self._hdcmem, self._hbmp.handle, 0, height, self._buf, ctypes.byref(self._bi), win32con.DIB_RGB_COLORS)
        # make a cv2 Image
        arr = np.fromstring(self._buf, dtype=np.uint8)
        img = arr.reshape(height, width, 4)
        img = img[::-1,:, 0:3]
        return img 
开发者ID:NetEaseGame,项目名称:ATX,代码行数:17,代码来源:windows.py


注:本文中的win32gui.GetDesktopWindow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。