本文整理匯總了Python中win32gui.GetWindowDC方法的典型用法代碼示例。如果您正苦於以下問題:Python win32gui.GetWindowDC方法的具體用法?Python win32gui.GetWindowDC怎麽用?Python win32gui.GetWindowDC使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊win32gui的用法示例。
在下文中一共展示了win32gui.GetWindowDC方法的18個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。
示例1: WindowDraw
點讚 6
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowDC [as 別名]
def WindowDraw(self, rect):
'''
Draws a rectangle to the window
'''
if self.hwnd is None:
return
#raise Exception("HWND is none. HWND not called or invalid window name provided.")
wDC = win32gui.GetWindowDC(self.hwnd)
dcObj = win32ui.CreateDCFromHandle(wDC)
#Set background mode to transparent
#dcObj.SetBkColor(0x12345)
#dcObj.SetBkMode(0)
dcObj.Rectangle(rect)
# Free Resources
dcObj.DeleteDC()
win32gui.ReleaseDC(self.hwnd, wDC)
開發者ID:nicholastoddsmith,項目名稱:poeai,代碼行數:18,
示例2: set_props
點讚 6
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowDC [as 別名]
def set_props( self, window = None, **kwargs ):
if window and self.roi:
win32gui.InvalidateRect( window.window_handle,
self.roi, True )
for key in ('text','rect','style','font','color'):
if key in kwargs:
setter = '_set_' + key
if hasattr( self, setter ):
getattr( self, setter )( kwargs[ key ] )
else:
setattr( self, key, kwargs[ key ] )
if window:
hdc = win32gui.GetWindowDC( window.window_handle )
roi = self.calc_roi( hdc )
win32gui.ReleaseDC( window.window_handle, hdc )
win32gui.InvalidateRect( window.window_handle,
roi, True )
開發者ID:mailpile,項目名稱:gui-o-matic,代碼行數:22,
示例3: get_bitmap
點讚 5
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowDC [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,
示例4: get_pixel_color
點讚 5
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowDC [as 別名]
def get_pixel_color(x :int, y :int, debug :bool =False) -> str:
"""Get the color of selected pixel in HEX."""
dc = win32gui.GetWindowDC(Window.id)
rgba = win32gui.GetPixel(dc, x + 8 + Window.x, y + 8 + Window.y)
win32gui.ReleaseDC(Window.id, dc)
r = rgba & 0xff
g = rgba >> 8 & 0xff
b = rgba >> 16 & 0xff
if debug: print(Inputs.rgb_to_hex((r, g, b)))
return Inputs.rgb_to_hex((r, g, b))
開發者ID:kujan,項目名稱:NGU-scripts,代碼行數:14,
示例5: GetScreenImg
點讚 5
# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import GetWindowDC [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)</