# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreateCompatibleBitmap [as 别名]
def screen(self):
"""PIL Image of current window screen. (the window must be on the top)
reference: https://msdn.microsoft.com/en-us/library/dd183402(v=vs.85).aspx"""
# opengl windows cannot get from it's hwnd, so we use the screen
hwnd = win32gui.GetDesktopWindow()
# get window 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