本文整理汇总了Python中win32gui.CreateCompatibleDC方法的典型用法代码示例。如果您正苦于以下问题:Python win32gui.CreateCompatibleDC方法的具体用法?Python win32gui.CreateCompatibleDC怎么用?Python win32gui.CreateCompatibleDC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32gui
的用法示例。
在下文中一共展示了win32gui.CreateCompatibleDC方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prep_menu_icon
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreateCompatibleDC [as 别名]
def prep_menu_icon(self, icon):
# First load the icon.
ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON)
ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON)
hicon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE)
hdcBitmap = win32gui.CreateCompatibleDC(0)
hdcScreen = win32gui.GetDC(0)
hbm = win32gui.CreateCompatibleBitmap(hdcScreen, ico_x, ico_y)
hbmOld = win32gui.SelectObject(hdcBitmap, hbm)
# Fill the background.
brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU)
win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush)
# unclear if brush needs to be feed. Best clue I can find is:
# "GetSysColorBrush returns a cached brush instead of allocating a new
# one." - implies no DeleteObject
# draw the icon
win32gui.DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0, win32con.DI_NORMAL)
win32gui.SelectObject(hdcBitmap, hbmOld)
win32gui.DeleteDC(hdcBitmap)
return hbm
示例2: prep_menu_icon
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreateCompatibleDC [as 别名]
def prep_menu_icon(self, icon):
# First load the icon.
ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON)
ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON)
hicon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y,
win32con.LR_LOADFROMFILE)
hdcBitmap = win32gui.CreateCompatibleDC(0)
hdcScreen = win32gui.GetDC(0)
hbm = win32gui.CreateCompatibleBitmap(hdcScreen, ico_x, ico_y)
hbmOld = win32gui.SelectObject(hdcBitmap, hbm)
# Fill the background.
brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU)
win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush)
# unclear if brush needs to be feed. Best clue I can find is:
# "GetSysColorBrush returns a cached brush instead of allocating a new
# one." - implies no DeleteObject
# draw the icon
win32gui.DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0,
win32con.DI_NORMAL)
win32gui.SelectObject(hdcBitmap, hbmOld)
win32gui.DeleteDC(hdcBitmap)
return hbm
示例3: prep_menu_icon
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreateCompatibleDC [as 别名]
def prep_menu_icon(self, icon):
# First load the icon.
ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON)
ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON)
hicon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE)
hdcBitmap = win32gui.CreateCompatibleDC(0)
hdcScreen = win32gui.GetDC(0)
hbm = win32gui.CreateCompatibleBitmap(hdcScreen, ico_x, ico_y)
hbmOld = win32gui.SelectObject(hdcBitmap, hbm)
# Fill the background.
brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU)
win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush)
# unclear if brush needs to be feed. Best clue I can find is:
# "GetSysColorBrush returns a cached brush instead of allocating a new
# one." - implies no DeleteObject
# draw the icon
win32gui.DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0, win32con.DI_NORMAL)
win32gui.SelectObject(hdcBitmap, hbmOld)
win32gui.DeleteDC(hdcBitmap)
return hbm
示例4: __call__
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreateCompatibleDC [as 别名]
def __call__( self, window, hdc, paint_struct ):
dirty = self.dirty( window )
if dirty:
self.update( window, hdc )
rect = self.rect or window.get_client_region()
roi = rect_intersect( rect, paint_struct[2] )
hdc_mem = win32gui.CreateCompatibleDC( hdc )
prior_bitmap = win32gui.SelectObject( hdc_mem, self.image.handle )
win32gui.BitBlt( hdc,
roi[0],
roi[1],
roi[2] - roi[0],
roi[3] - roi[1],
hdc_mem,
roi[0] - rect[0],
roi[1] - rect[1],
win32con.SRCCOPY )
win32gui.SelectObject( hdc_mem, prior_bitmap )
win32gui.DeleteDC( hdc_mem )
示例5: __init_screen_handles
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreateCompatibleDC [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
示例6: screen
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreateCompatibleDC [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
win32gui.SelectObject(hdcmem, hbmp)
# copy bits to temporary dc
win32gui.BitBlt(hdcmem, 0, 0, width, height,
hdcwin, left, top, win32con.SRCCOPY)
# 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)()
# read bits into buffer
windll.gdi32.GetDIBits(hdcmem, hbmp.handle, 0, bmp.bmHeight, buf, ctypes.byref(bi), win32con.DIB_RGB_COLORS)
# make a PIL Image
img = Image.frombuffer('RGB', (bmp.bmWidth, bmp.bmHeight), buf, 'raw', 'BGRX', 0, 1)
img = img.transpose(Image.FLIP_TOP_BOTTOM)
# cleanup
win32gui.DeleteObject(hbmp)
win32gui.DeleteObject(hdcmem)
win32gui.ReleaseDC(hwnd, hdcwin)
return img