本文整理匯總了Python中win32gui.SelectObject方法的典型用法代碼示例。如果您正苦於以下問題:Python win32gui.SelectObject方法的具體用法?Python win32gui.SelectObject怎麽用?Python win32gui.SelectObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類win32gui
的用法示例。
在下文中一共展示了win32gui.SelectObject方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: OnPaint_1
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SelectObject [as 別名]
def OnPaint_1(hwnd, msg, wp, lp):
dc, ps=win32gui.BeginPaint(hwnd)
win32gui.SetGraphicsMode(dc, win32con.GM_ADVANCED)
br=win32gui.CreateSolidBrush(win32api.RGB(255,0,0))
win32gui.SelectObject(dc, br)
angle=win32gui.GetWindowLong(hwnd, win32con.GWL_USERDATA)
win32gui.SetWindowLong(hwnd, win32con.GWL_USERDATA, angle+2)
r_angle=angle*(math.pi/180)
win32gui.SetWorldTransform(dc,
{'M11':math.cos(r_angle), 'M12':math.sin(r_angle), 'M21':math.sin(r_angle)*-1, 'M22':math.cos(r_angle),'Dx':250,'Dy':250})
win32gui.MoveToEx(dc,250,250)
win32gui.BeginPath(dc)
win32gui.Pie(dc, 10, 70, 200, 200, 350, 350, 75, 10)
win32gui.Chord(dc, 200, 200, 850, 0, 350, 350, 75, 10)
win32gui.LineTo(dc, 300,300)
win32gui.LineTo(dc, 100, 20)
win32gui.LineTo(dc, 20, 100)
win32gui.LineTo(dc, 400, 0)
win32gui.LineTo(dc, 0, 400)
win32gui.EndPath(dc)
win32gui.StrokeAndFillPath(dc)
win32gui.EndPaint(hwnd, ps)
return 0
示例2: prep_menu_icon
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SelectObject [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 SelectObject [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: prep_menu_icon
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SelectObject [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
示例5: __call__
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SelectObject [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 )
示例6: __init_screen_handles
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SelectObject [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
示例7: screen
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SelectObject [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