def sendQ(telephone,code): # 设置部分 windowtitle = '骑着码去嗨' # 窗口名 hwnd = win32gui.FindWindow(None, windowtitle) # 设置剪贴板文本 aString = telephone +" "+ code # 需要发送得信息 w.OpenClipboard() w.EmptyClipboard() w.SetClipboardData(win32con.CF_UNICODETEXT, aString) # 测试剪贴板文本 w.CloseClipboard() w.OpenClipboard() d = w.GetClipboardData(win32con.CF_UNICODETEXT) w.CloseClipboard() print(d) # 发送部分 win32gui.PostMessage(hwnd,win32con.WM_PASTE, 0, 0) # 向窗口发送剪贴板内容(粘贴) QQ测试可以正常发送 time.sleep(0.3) win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0) # 向窗口发送 回车键 win32gui.PostMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0) # 实现功能部分 print('找到%s' % windowtitle) left, top, right, bottom = win32gui.GetWindowRect(hwnd) # 窗口获取坐标 print(left, top, right, bottom) print('窗口尺寸', right - left, bottom - top) win32gui.MoveWindow(hwnd, 20, 20, 405, 756, True) # 改变窗口大小 time.sleep(6) win32gui.SetBkMode(hwnd, win32con.TRANSPARENT) # 设置为后台
def OnPaint(self, hwnd, msg, wp, lp): dc, ps = win32gui.BeginPaint(hwnd) wndrect = win32gui.GetClientRect(hwnd) wndwidth = wndrect[2] - wndrect[0] wndheight = wndrect[3] - wndrect[1] win32clipboard.OpenClipboard() try: try: hbitmap = win32clipboard.GetClipboardData( win32clipboard.CF_BITMAP) except TypeError: font = win32gui.LOGFONT() font.lfHeight = 15 #int(wndheight/20) font.lfWidth = 15 #font.lfHeight # font.lfWeight=150 hf = win32gui.CreateFontIndirect(font) win32gui.SelectObject(dc, hf) win32gui.SetBkMode(dc, win32con.TRANSPARENT) win32gui.SetTextColor(dc, win32api.RGB(0, 0, 0)) win32gui.DrawText( dc, 'No bitmaps are in the clipboard\n(try pressing the PrtScn button)', -1, (0, 0, wndwidth, wndheight), win32con.DT_CENTER) else: bminfo = win32gui.GetObject(hbitmap) dcDC = win32gui.CreateCompatibleDC(None) win32gui.SelectObject(dcDC, hbitmap) win32gui.StretchBlt(dc, 0, 0, wndwidth, wndheight, dcDC, 0, 0, bminfo.bmWidth, bminfo.bmHeight, win32con.SRCCOPY) win32gui.DeleteDC(dcDC) win32gui.EndPaint(hwnd, ps) finally: win32clipboard.CloseClipboard() return 0
def begin_document(self, desc = "MSWinPrint.py print job"): # open the printer if self.printer is None: self.printer = win32print.GetDefaultPrinter() self.hprinter = win32print.OpenPrinter(self.printer) # load default settings devmode = win32print.GetPrinter(self.hprinter, 8)["pDevMode"] # change paper size and orientation if self.papersize is not None: if type(self.papersize) is int: devmode.PaperSize = self.papersize else: devmode.PaperSize = paper_sizes[self.papersize] if self.orientation is not None: devmode.Orientation = orientations[self.orientation] if self.duplex is not None: devmode.Duplex = duplexes[self.duplex] # create dc using new settings self.hdc = win32gui.CreateDC("WINSPOOL", self.printer, devmode) self.dc = win32ui.CreateDCFromHandle(self.hdc) # self.dc = win32ui.CreateDC() # if self.printer is not None: # self.dc.CreatePrinterDC(self.printer) # else: # self.dc.CreatePrinterDC() self.dc.SetMapMode(win32con.MM_TWIPS) # hundredths of inches self.dc.StartDoc(desc) self.dc.SetBkMode(win32con.TRANSPARENT) self.pen = win32ui.CreatePen(0, int(scale_factor), 0L) self.dc.SelectObject(self.pen) win32gui.SetBkMode(self.hdc, 1) # transparent self.page = 1
def sendAQQMessage(self, msg, logger=None): # 将测试消息复制到剪切板中 w.OpenClipboard() w.EmptyClipboard() w.SetClipboardData(win32con.CF_UNICODETEXT, msg) w.CloseClipboard() logger.info('%s复制到剪切板中' % msg) # 获取窗口句柄 handle = win32gui.FindWindow(0, self.name) # 还原 win32gui.SendMessage(handle, win32con.WM_SYSCOMMAND, win32con.SC_RESTORE, 0) # 设为高亮 win32gui.SetForegroundWindow(handle) # 填充消息 win32gui.SendMessage(handle, 770, 0, 0) logger.info('在(%s)窗口中填充消息:%s' % (self.name, msg)) # 回车发送消息 win32gui.SendMessage(handle, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0) logger.info('回车发送') win32gui.SetBkMode(handle, win32con.TRANSPARENT) win32gui.ShowWindow(handle, win32con.SW_MINIMIZE)
def WndProc(self, hWnd, message, wParam, lParam): if message == win32con.WM_PAINT: rect = win32gui.GetClientRect(hWnd) # tuple(L,T,R,B) hDC, paintStruct = win32gui.BeginPaint(hWnd) win32gui.SetTextColor(hDC, win32api.RGB(255, 0, 0)) win32gui.SetBkMode(hDC, 1) rect2 = (rect[0] + 10, rect[1] + 10, rect[2], rect[3]) rect3 = (rect[0] + 10, rect[1] + 30, rect[2], rect[3]) win32gui.DrawText(hDC, 'Overlay Test', -1, rect2, win32con.DT_SINGLELINE | win32con.DT_NOCLIP) win32gui.DrawText(hDC, 'Test message2', -1, rect3, win32con.DT_SINGLELINE | win32con.DT_NOCLIP) ### memDC = win32gui.CreateCompatibleDC(hDC) image1 = win32gui.LoadImage(None, "1111.bmp", win32con.IMAGE_BITMAP, 0, 0, win32con.LR_LOADFROMFILE) OldBitmap = win32gui.SelectObject(memDC, image1) if image1 == 0: print("image load error") exit(1) win32gui.BitBlt(hDC, 10, 50, 100, 100, memDC, 0, 0, win32con.SRCCOPY) win32gui.SelectObject(memDC, OldBitmap) win32gui.DeleteObject(image1) win32gui.DeleteObject(memDC) win32gui.EndPaint(hWnd, paintStruct) elif message == win32con.WM_DESTROY: print("Being destroyed") win32gui.PostQuitMessage(0) else: return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
def set_hwnd_backgroud(targetTitle): hwnd = get_window_hwnd(targetTitle) if hwnd is not None: win32gui.SetBkMode(hwnd, win32con.TRANSPARENT) print("ok")
desktopwidth, desktopheight, win32con.SRCCOPY) win32print.StartDoc(pDC, ('desktop.bmp', None, None, 0)) win32print.StartPage(pDC) win32gui.StretchBlt(pDC, 0, 0, int(printerwidth * .9), int(printerheight * .9), pcDC, 0, 0, printerwidth, printerheight, win32con.SRCCOPY) font = win32gui.LOGFONT() font.lfHeight = int(printerheight / 20) font.lfWidth = font.lfHeight font.lfWeight = 150 font.lfItalic = 1 font.lfUnderline = 1 hf = win32gui.CreateFontIndirect(font) win32gui.SelectObject(pDC, hf) win32gui.SetBkMode(pDC, win32con.TRANSPARENT) win32gui.SetTextColor(pDC, win32api.RGB(0, 255, 0)) win32gui.DrawText( pDC, 'Printed by Python!', -1, (0, 0, int(printerwidth * .9), int(printerheight * .9)), win32con.DT_RIGHT | win32con.DT_BOTTOM | win32con.DT_SINGLELINE) win32print.EndPage(pDC) win32print.EndDoc(pDC) win32print.ClosePrinter(p) win32gui.DeleteObject(dcBM) win32gui.DeleteObject(pcBM) win32gui.DeleteObject(hf) win32gui.DeleteDC(dDC) win32gui.DeleteDC(dcDC) win32gui.DeleteDC(pDC)
# 设置剪贴板文本 aString = "test" w.OpenClipboard() w.EmptyClipboard() w.SetClipboardData(win32con.CF_UNICODETEXT, aString) # 测试剪贴板文本 w.CloseClipboard() w.OpenClipboard() d = w.GetClipboardData(win32con.CF_UNICODETEXT) w.CloseClipboard() print(d) # 发送部分 win32gui.PostMessage(hwnd, win32con.WM_PASTE, 0, 0) # 向窗口发送剪贴板内容(粘贴) QQ测试可以正常发送 time.sleep(0.3) win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0) # 向窗口发送 回车键 win32gui.PostMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0) # 实现功能部分 print('找到%s' % windowtitle) left, top, right, bottom = win32gui.GetWindowRect(hwnd) # 窗口获取坐标 print(left, top, right, bottom) print('窗口尺寸', right - left, bottom - top) win32gui.MoveWindow(hwnd, 20, 20, 405, 756, True) # 改变窗口大小 time.sleep(6) win32gui.SetBkMode(hwnd, win32con.TRANSPARENT) # 设置为后台 time.sleep(2)
def renderText(self, text, bg, fg, wrap=False, max_x=100, max_y=None): self.drawDC.SetTextColor(Wcolour(fg)) t = self.drawDC.GetSafeHdc() win32gui.SetBkMode(t, win32con.TRANSPARENT) #create the compatible bitmap: #w,h = self.drawDC.GetTextExtent(text) w, h = self.get_metrics(text, max_x, wrap) #print(self.drawDC.GetTextFace()) #w += 1 #if wrap: # h = int((w / max_x) * h) + h # w = max_x + 1 if max_y != None: h = max_y saveBitMap = win32ui.CreateBitmap() saveBitMap.CreateCompatibleBitmap(self.mfcDC, w, h) self.drawDC.SelectObject(saveBitMap) #draw it br = win32ui.CreateBrush(win32con.BS_SOLID, Wcolour(bg), 0) self.drawDC.FillRect((0, 0, w, h), br) #self.drawDC.DrawText(text, (0, 0, w, h), win32con.DT_LEFT) #windll.gdi32.TextOutW(t, 0, 0, "test", 5) if wrap: rect = RECT(0, 0, 0, 0) rect.left = 0 rect.right = round(max_x) rect.top = 0 rect.bottom = round(h) #windll.User32.DrawTextW(t, text, len(text)) #, rect, win32con.DT_WORDBREAK) windll.User32.DrawTextW(t, text, len(text), pointer(rect), win32con.DT_WORDBREAK) else: rect = RECT(0, 0, 0, 0) rect.left = 0 rect.right = round(max_x) rect.top = 0 rect.bottom = round(h) #windll.User32.DrawTextW(t, text, len(text)) #, rect, win32con.DT_WORDBREAK) windll.User32.DrawTextW(t, text, len(text), pointer(rect), win32con.DT_END_ELLIPSIS) #windll.gdi32.TextOutW(t, 0, 0, text, len(text)) # print(rects) #print(text) #windll.gdi32.ExtTextOutW(t, 0, 0, None, rect, text, len(text), None) #convert to SDL surface im, c_bits = native_bmp_to_sdl(self.drawDC.GetSafeHdc(), saveBitMap.GetHandle(), w, h) #clean-up win32gui.DeleteObject(saveBitMap.GetHandle()) return im, c_bits
def 窗口_置后台(窗口句柄): '设置为后台' return win32gui.SetBkMode(窗口句柄, win32con.TRANSPARENT)
def __init__(self, style: Style): self.family = style.fontname self.bold = style.bold self.italic = style.italic self.underline = style.underline self.strikeout = style.strikeout self.size = style.fontsize self.xscale = style.scale_x / 100 self.yscale = style.scale_y / 100 self.hspace = style.spacing self.upscale = FONT_PRECISION self.downscale = 1 / FONT_PRECISION if sys.platform == "win32": # Create device context self.dc = win32gui.CreateCompatibleDC(None) # Set context coordinates mapping mode win32gui.SetMapMode(self.dc, win32con.MM_TEXT) # Set context backgrounds to transparent win32gui.SetBkMode(self.dc, win32con.TRANSPARENT) # Create font handle font_spec = { "height": int(self.size * self.upscale), "width": 0, "escapement": 0, "orientation": 0, "weight": win32con.FW_BOLD if self.bold else win32con.FW_NORMAL, "italic": int(self.italic), "underline": int(self.underline), "strike out": int(self.strikeout), "charset": win32con.DEFAULT_CHARSET, "out precision": win32con.OUT_TT_PRECIS, "clip precision": win32con.CLIP_DEFAULT_PRECIS, "quality": win32con.ANTIALIASED_QUALITY, "pitch and family": win32con.DEFAULT_PITCH + win32con.FF_DONTCARE, "name": self.family, } self.pycfont = win32ui.CreateFont(font_spec) win32gui.SelectObject(self.dc, self.pycfont.GetSafeHandle()) # Calculate metrics self.metrics = win32gui.GetTextMetrics(self.dc) elif sys.platform == "linux" or sys.platform == "darwin": surface = cairo.ImageSurface(cairo.Format.A8, 1, 1) self.context = cairo.Context(surface) self.layout = PangoCairo.create_layout(self.context) font_description = Pango.FontDescription() font_description.set_family(self.family) font_description.set_absolute_size(self.size * self.upscale * PANGO_SCALE) font_description.set_weight( Pango.Weight.BOLD if self.bold else Pango.Weight.NORMAL) font_description.set_style( Pango.Style.ITALIC if self.italic else Pango.Style.NORMAL) self.layout.set_font_description(font_description) self.metrics = Pango.Context.get_metrics( self.layout.get_context(), self.layout.get_font_description()) if LIBASS_FONTHACK: self.fonthack_scale = self.size / ( (self.metrics.get_ascent() + self.metrics.get_descent()) / PANGO_SCALE * self.downscale) else: self.fonthack_scale = 1 else: raise NotImplementedError
def set_back(s): h = get_handle(s) if h != 0: win32gui.SetBkMode(h, win32con.TRANSPARENT)
def create_window(self): def wndProc(hWnd, message, wParam, lParam): if message == self.MESSAGE: if lParam == win32con.WM_RBUTTONUP: self.show_menu() return 0 elif message == win32con.WM_COMMAND: self.execute_menu_item(win32gui.LOWORD(wParam)) return 0 elif message == self.__MESSAGE_TC: # TaskbarCreated message indicates all tray icons have been removed, # so we should add our tray icon again, not updating it. self.__NOTIFY_ID = None self.update_tray_icon() return 0 elif message == win32con.WM_PAINT: hdc, paintStruct = win32gui.BeginPaint(hWnd) if self.font is None: self.init_font(hdc, paintStruct) # Set the font win32gui.SelectObject(hdc, self.font) text = str(self.key_count) # Clear window content win32gui.DefWindowProc(hWnd, message, wParam, lParam) # Dynamically change window size & position if necessary text_extent = win32gui.GetTextExtentPoint32(hdc, text) window_rect = win32gui.GetClientRect(hWnd) window_width = window_rect[2] - window_rect[0] window_height = window_rect[3] - window_rect[1] if window_width != text_extent[0]\ or window_height != text_extent[1]: pass _, _, screen_width, screen_height = get_workarea_rect() win32gui.SetWindowPos( self.HWND, None, screen_width - text_extent[0], # x screen_height - text_extent[1], # y text_extent[0], # width text_extent[1], # height 0) # http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx win32gui.DrawText( hdc, text, len(text), # somehow -1 does not work tuple(win32gui.GetClientRect(hWnd)), (win32con.DT_BOTTOM | win32con.DT_NOCLIP | win32con.DT_SINGLELINE | win32con.DT_RIGHT)) self.__last_text_extent = text_extent win32gui.EndPaint(hWnd, paintStruct) return 0 elif message == win32con.WM_CLOSE: self.log('Window is closing, saving data now') super(KeyCounter, self).stop() return win32gui.DefWindowProc(hWnd, message, wParam, lParam) # The operating system wants to end the session elif message == win32con.WM_QUERYENDSESSION: self.log('Session might end soon, saving data now') super(KeyCounter, self).stop() return win32gui.DefWindowProc(hWnd, message, wParam, lParam) # The operating system is ending the session elif message == win32con.WM_ENDSESSION: self.log('Session %s ending', 'is' if wParam == win32con.TRUE else 'is not') super(KeyCounter, self).stop() return win32gui.DefWindowProc(hWnd, message, wParam, lParam) else: return win32gui.DefWindowProc(hWnd, message, wParam, lParam) hInstance = win32api.GetModuleHandle() className = 'TransparentWindow' # http://msdn.microsoft.com/en-us/library/windows/desktop/ms633576(v=vs.85).aspx # win32gui does not support WNDCLASSEX. wndClass = win32gui.WNDCLASS() # http://msdn.microsoft.com/en-us/library/windows/desktop/ff729176(v=vs.85).aspx wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW wndClass.lpfnWndProc = wndProc wndClass.hInstance = hInstance wndClass.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW) wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH) wndClass.lpszClassName = className # win32gui does not support RegisterClassEx wndClassAtom = win32gui.RegisterClass(wndClass) # http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx # Consider using: # WS_EX_COMPOSITED, WS_EX_LAYERED, WS_EX_NOACTIVATE, # WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_EX_TRANSPARENT # The WS_EX_TRANSPARENT flag makes events (like mouse clicks) # fall through the window. exStyle = (win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT | win32con.WS_EX_TOOLWINDOW) # http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx # Consider using: WS_DISABLED, WS_POPUP, WS_VISIBLE style = win32con.WS_DISABLED | win32con.WS_POPUP | win32con.WS_VISIBLE _, _, screen_width, screen_height = get_workarea_rect() # We'll update window size if we need more space init_width = 1 init_height = 1 hWindow = win32gui.CreateWindowEx( exStyle, wndClassAtom, None, # WindowName style, screen_width - init_width, # x screen_height - init_height, # y init_width, # width init_height, # height None, # hWndParent None, # hMenu hInstance, None # lpParam ) self.HWND = hWindow # Foreground transparency of 208 looks good # http://msdn.microsoft.com/en-us/library/windows/desktop/ms633540(v=vs.85).aspx win32gui.SetLayeredWindowAttributes( self.HWND, 0x00ffffff, 208, # foreground transparency, 255 means opaque win32con.LWA_COLORKEY | win32con.LWA_ALPHA) # Transparent background win32gui.SetBkMode(hWindow, win32con.TRANSPARENT) # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145167(v=vs.85).aspx # win32gui.UpdateWindow(hWindow) # http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx win32gui.SetWindowPos( hWindow, win32con.HWND_TOPMOST, screen_width - init_width, # x screen_height - init_height, # y init_width, # width init_height, # height (win32con.SWP_NOACTIVATE | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW))
def wnd_proc(h_wnd, message, w_param, l_param): """Displays a transparent window with some graphic elements Displays a transparent window with some graphic elements :param h_wnd: an input argument :returns: nothing """ if message == win32con.WM_QUIT: # print("Closing the window overlay") win32gui.PostQuitMessage(0) return 0 if message == win32con.WM_PAINT: hdc, paint_struct = win32gui.BeginPaint(h_wnd) win32gui.SetGraphicsMode(hdc, win32con.GM_ADVANCED) win32gui.BringWindowToTop(h_wnd) for r in self.graphical_elements: if 'geometry' in r: geometry = r['geometry'] else: geometry = None if 'x' in r: x = r['x'] - self.x_min else: x = 0 if 'y' in r: y = r['y'] - self.y_min else: y = 0 if 'width' in r: width = r['width'] else: width = 100 if 'height' in r: height = r['height'] else: height = 100 if 'xyrgb_array' in r: xyrgb_array = r['xyrgb_array'] else: xyrgb_array = ((15, 15, 255, 0, 0), (15, 45, 0, 255, 0), (45, 30, 0, 0, 255)) if 'color' in r: color_r = r['color'][0] color_g = r['color'][1] color_b = r['color'][2] else: color_r = 255 color_g = 0 color_b = 0 if 'thickness' in r: thickness = r['thickness'] else: thickness = 0 if 'angle' in r: angle = r['angle'] else: angle = 0 if 'geometry' in r and r['geometry'] is Shape.triangle: vertices = () for xyrgb in xyrgb_array: vertices = vertices + ( { 'x': int(round(xyrgb[0])) - self.x_min, 'y': int(round(xyrgb[1])) - self.y_min, 'Red': xyrgb[2] * 256, 'Green': xyrgb[3] * 256, 'Blue': xyrgb[4] * 256, 'Alpha': 0 }, ) mesh = ((0, 1, 2), ) win32gui.GradientFill(hdc, vertices, mesh, win32con.GRADIENT_FILL_TRIANGLE) if 'brush_color' in r: brush_color_r = r['brush_color'][0] brush_color_g = r['brush_color'][1] brush_color_b = r['brush_color'][2] else: brush_color_r = 255 brush_color_g = 255 brush_color_b = 255 if thickness == 0: color_r = brush_color_r color_g = brush_color_g color_b = brush_color_b if 'font_size' in r: font_size = r['font_size'] else: font_size = 18 if 'font_name' in r: font_name = r['font_name'] else: font_name = "Arial" my_brush = None if 'brush' in r and width > 1 and height > 1: brush = r['brush'] brush_color = win32api.RGB(brush_color_r, brush_color_g, brush_color_b) if brush is Brush.solid: my_brush = win32gui.CreateSolidBrush(brush_color) elif brush is Brush.b_diagonal: my_brush = win32gui.CreateHatchBrush( win32con.HS_BDIAGONAL, brush_color) elif brush is Brush.cross: my_brush = win32gui.CreateHatchBrush( win32con.HS_CROSS, brush_color) elif brush is Brush.diag_cross: my_brush = win32gui.CreateHatchBrush( win32con.HS_DIAGCROSS, brush_color) elif brush is Brush.f_diagonal: my_brush = win32gui.CreateHatchBrush( win32con.HS_FDIAGONAL, brush_color) elif brush is Brush.horizontal: my_brush = win32gui.CreateHatchBrush( win32con.HS_HORIZONTAL, brush_color) elif brush is Brush.vertical: my_brush = win32gui.CreateHatchBrush( win32con.HS_VERTICAL, brush_color) old_brush = win32gui.SelectObject(hdc, my_brush) pen = win32gui.CreatePen( win32con.PS_GEOMETRIC, thickness, win32api.RGB(color_r, color_g, color_b)) old_pen = win32gui.SelectObject(hdc, pen) if 'center_of_rotation' in r: center_of_rotation_x = r['center_of_rotation'][0] center_of_rotation_y = r['center_of_rotation'][1] else: center_of_rotation_x = 0 center_of_rotation_y = 0 if angle != 0: r_angle = angle * (math.pi / 180) Py_XFORM = win32gui.GetWorldTransform(hdc) win32gui.SetWorldTransform( hdc, { 'M11': math.cos(r_angle), 'M12': math.sin(r_angle), 'M21': math.sin(r_angle) * -1, 'M22': math.cos(r_angle), 'Dx': x, 'Dy': y }) x, y = -center_of_rotation_x, -center_of_rotation_y if 'text_format' in r: text_format = eval(r['text_format']) else: text_format = win32con.DT_CENTER | win32con.DT_SINGLELINE | win32con.DT_VCENTER if 'geometry' in r: if r['geometry'] is Shape.rectangle: win32gui.Rectangle(hdc, int(round(x)), int(round(y)), int(round(x + width)), int(round(y + height))) elif r['geometry'] is Shape.ellipse: win32gui.Ellipse(hdc, int(round(x)), int(round(y)), int(round(x + width)), int(round(y + height))) elif r['geometry'] is Shape.arrow: a = thickness t = ((x - int(a * 1.4), y), (x - a * 4, y + a * 3), (x, y), (x - a * 4, y - a * 3), (x - int(a * 1.4), y), (x - a * 9, y)) win32gui.Polyline(hdc, t) elif r['geometry'] is Shape.image: hicon = r['hicon'] win32gui.DrawIconEx(hdc, x, y, hicon, 0, 0, 0, None, 0x0003) elif r['geometry'] is Shape.triangle and thickness > 0: t = () for xyrgb in xyrgb_array: t = t + ((int(round( xyrgb[0])), +int(round(xyrgb[1]))), ) t = t + ((int(round(xyrgb_array[0][0])), int(round(xyrgb_array[0][1]))), ) win32gui.Polyline(hdc, t) if angle != 0: win32gui.SetWorldTransform(hdc, Py_XFORM) win32gui.SelectObject(hdc, old_pen) if 'brush' in r and width > 1 and height > 1: win32gui.SelectObject(hdc, old_brush) if 'text' in r: text = r['text'] lf = win32gui.LOGFONT() lf.lfFaceName = font_name lf.lfHeight = font_size lf.lfWeight = win32con.FW_NORMAL lf.lfQuality = win32con.ANTIALIASED_QUALITY hf = win32gui.CreateFontIndirect(lf) old_font = win32gui.SelectObject(hdc, hf) if 'text_color' in r: text_color_r = r['text_color'][0] text_color_g = r['text_color'][1] text_color_b = r['text_color'][2] else: text_color_r = 0 text_color_g = 0 text_color_b = 0 win32gui.SetTextColor( hdc, win32api.RGB(text_color_r, text_color_g, text_color_b)) if 'text_bg_color' in r: text_bg_color_r = r['text_bg_color'][0] text_bg_color_g = r['text_bg_color'][1] text_bg_color_b = r['text_bg_color'][2] else: text_bg_color_r = brush_color_r text_bg_color_g = brush_color_g text_bg_color_b = brush_color_b win32gui.SetBkMode(hdc, win32con.TRANSPARENT) win32gui.SetBkColor( hdc, win32api.RGB(text_bg_color_r, text_bg_color_g, text_bg_color_b)) tuple_r = tuple([ int(round(x)), int(round(y)), int(round(x + width)), int(round(y + height)) ]) win32gui.DrawTextW(hdc, text, -1, tuple_r, text_format) win32gui.SelectObject(hdc, old_font) win32gui.EndPaint(h_wnd, paint_struct) return 0 else: return win32gui.DefWindowProc(h_wnd, message, w_param, l_param)