def drawCrossHair(hDc, centerX, centerY, size=10, lineWidth=1, color=COLOR_RED): hPen= win32gui.CreatePen(win32con.PS_SOLID, lineWidth, color) win32gui.SelectObject(hDc, hPen) win32gui.MoveToEx(hDc, centerX-size, centerY) win32gui.LineTo(hDc, centerX+size, centerY) win32gui.MoveToEx(hDc, centerX, centerY+size) win32gui.LineTo(hDc, centerX, centerY-size)
def __init__(self, parent = None): QtGui.QLabel.__init__(self, parent) self.parent = parent self.spying = False self.rectanglePen = win32gui.CreatePen(win32con.PS_SOLID, 3, win32api.RGB(255, 0, 0)) self.prevWindow = None self.setCursor(QtCore.Qt.SizeAllCursor)
def setPenColor(self, r, g, b): self.hbrush = win32gui.GetStockObject( win32con.NULL_BRUSH) # 定义透明画刷,这个很重要!! self.hPen = win32gui.CreatePen(win32con.PS_SOLID, 2, win32api.RGB(r, g, b)) # 定义框颜色 win32gui.SelectObject(self.hwndDC, self.hPen) self.prebrush = win32gui.SelectObject(self.hwndDC, self.hbrush) win32gui.SelectObject(self.hwndDC, self.prebrush)
def line(self, p1, p2, t, color): if p1 is None or p2 is None: return pen = win32gui.CreatePen(win32con.PS_SOLID, t, win32api.RGB(*color)) hoPen = win32gui.SelectObject(self.hdc, pen) win32gui.MoveToEx(self.hdc, p1[0], p1[1]) win32gui.LineTo(self.hdc, p2[0], p2[1]) win32gui.DeleteObject(win32gui.SelectObject(self.hdc, hoPen))
def circle(self, point, radius, t, color): if point is None: return x, y = point pen = win32gui.CreatePen(win32con.PS_SOLID, t, win32api.RGB(*color)) hoPen = win32gui.SelectObject(self.hdc, pen) win32gui.Arc(self.hdc, x - radius, y - radius, x + radius, y + radius, 0, 0, 0, 0) win32gui.DeleteObject(win32gui.SelectObject(self.hdc, hoPen))
def drawRightArc(self, hdc, pos, radius, width, span, percent, color=ColorCode.BLACK): if percent > 0.0: # Get arc center coordinates xc = pos[0] yc = pos[1] # Calculate a2 a1 = math.radians(span / 2) a2 = math.asin(radius * math.sin(a1) / (radius + width)) # calculate displacement on x and y axis dx = radius * math.cos(a2) dy = radius * math.sin(a2) # calculate starting point coordinates xs = int(xc + dx) ys = int(yc + dy) a2d = math.degrees(a2) # determines arc span span = 2 * a2d # sets the percentage to be drawn n = percent # sets arc fill color sb = win32gui.CreateSolidBrush(color) win32gui.SelectObject(hdc, sb) # sets arc stroke sp = win32gui.CreatePen(win32con.PS_SOLID, 1, ColorCode.BLACK) win32gui.SelectObject(hdc, sp) # draws the outline of the arc win32gui.BeginPath(hdc) win32gui.MoveToEx(hdc, xs, ys) win32gui.AngleArc(hdc, xc, yc, radius + width, -a2d, int(n * span)) win32gui.AngleArc(hdc, xc, yc, radius, int(a2d - (1 - n) * span), -int(n * span)) win32gui.EndPath(hdc) # fills the arc with outer stroke win32gui.StrokeAndFillPath(hdc) # returns the next arc span and radius return span, (radius + width) else: # if its not drawn, returns original arc span and radius return span, radius
def elipse(self, point, r_alpha, r_beta, t, color): if point is None: return x, y = point pen = win32gui.CreatePen(win32con.PS_SOLID, t, win32api.RGB(*color)) hoPen = win32gui.SelectObject(self.hdc, pen) win32gui.Arc(self.hdc, x - r_alpha, y - r_beta, x + r_alpha, y + r_beta, 0, 0, 0, 0) win32gui.DeleteObject(win32gui.SelectObject(self.hdc, hoPen))
def draw_focus_rectangle(cls, region: Region) -> None: """Draw a highlight region around given region Args: region (Region): [description] """ dc = win32gui.GetDC(0) pen = win32gui.CreatePen(win32con.PS_SOLID, 2, 0) win32gui.DrawFocusRect(dc, region.to_tuple()) win32gui.SelectObject(dc, pen) win32gui.DeleteDC(dc)
def __init__(self, parent=None): QLabel.__init__(self, parent) self.parent = parent self.spying = False self.rectanglePen = win32gui.CreatePen(win32con.PS_SOLID, 3, win32api.RGB(255, 0, 0)) self.prevWindow = None self.setCursor(QtCore.Qt.SizeAllCursor) self.spyingCur = QCursor(QPixmap('resource/img/window/searchw.cur')) self.setGeometry(QtCore.QRect(170, 20, 41, 41)) self.setPixmap(QtGui.QPixmap("resource/img/window/finderf.bmp")) self.setToolTip('在上面的窗口选择器上按下鼠标左键,\n拖动到要辅助的游戏窗口上,\n松开鼠标左键完成选择')
def hightligt_window(handle): left, top, right, bottom = win32gui.GetWindowRect(handle) rectanglePen = win32gui.CreatePen(win32con.PS_SOLID, 3, win32api.RGB(255, 0, 0)) windowDc = win32gui.GetWindowDC(handle) if windowDc: prevPen = win32gui.SelectObject(windowDc, rectanglePen) prevBrush = win32gui.SelectObject( windowDc, win32gui.GetStockObject(win32con.HOLLOW_BRUSH)) win32gui.Rectangle(windowDc, 0, 0, right - left, bottom - top) win32gui.SelectObject(windowDc, prevPen) win32gui.SelectObject(windowDc, prevBrush) win32gui.ReleaseDC(handle, windowDc)
def highLight(self): """高亮此区域 """ hwnd = win32gui.GetDesktopWindow() hDesktopDC = win32gui.GetWindowDC(hwnd) oldRop2 = ctypes.windll.gdi32.SetROP2(hDesktopDC, win32con.R2_NOTXORPEN) newPen = win32gui.CreatePen(win32con.PS_SOLID, 3, 0) oldPen = win32gui.SelectObject(hDesktopDC, newPen) #在指示窗口周围显示闪烁矩形 for i in range(2): win32gui.Rectangle(hDesktopDC, self._rect[0], self._rect[1], self._rect[2], self._rect[3]) time.sleep(0.2) win32gui.Rectangle(hDesktopDC, self._rect[0], self._rect[1], self._rect[2], self._rect[3]) time.sleep(0.3) ctypes.windll.gdi32.SetROP2(hDesktopDC, oldRop2) win32gui.SelectObject(hDesktopDC, oldPen) win32gui.DeleteObject(newPen) win32gui.ReleaseDC(hwnd,hDesktopDC)
def draw_pixel(): hwin = win32gui.GetDesktopWindow() hdc = win32gui.GetDC(hwin) # 점찍기 red = win32api.RGB(255, 0, 0) win32gui.SetPixel(hdc, 0, 0, red) win32gui.SetPixel(hdc, 0, 1, red) win32gui.SetPixel(hdc, 0, 2, red) win32gui.SetPixel(hdc, 0, 3, red) # 사각형그리기 pen = win32gui.CreatePen(win32con.PS_SOLID, 5, win32api.RGB(0, 0, 255)) oldPen = win32gui.SelectObject(hdc, pen) win32gui.Rectangle(hdc, 50, 50, 100, 100) win32gui.SelectObject(hdc, oldPen) win32gui.DeleteObject(pen)
def draw_line(cls, points: List[Point2D], color: RGB = None) -> None: """[summary] Args: points (List[Point2D]): [description] color (RGB, optional): [description]. Defaults to None. """ if not color: color = RGB(0, 255, 0) # GetDC(hwnd), jos haluaa nimenomaan tietylle ikkunalle... dc = win32gui.GetDC(0) pen = win32gui.CreatePen(win32con.PS_SOLID, 2, color.to_color_ref()) win32gui.SelectObject(dc, pen) lista = [p.to_tuple() for p in points] win32gui.Polyline(dc, lista) win32gui.DeleteObject(pen) win32gui.DeleteDC(dc)
def on_paint(self, hwnd, message, wparam, lparam): """Draw current selection rectangle.""" hdc, paint = win32gui.BeginPaint(hwnd) # Selection not started yet if self._selection is None: win32gui.EndPaint(hwnd, paint) return 0 brush = win32gui.GetStockObject(win32con.NULL_BRUSH) pen = win32gui.CreatePen(win32con.PS_SOLID, self.REGION_WIDTH, self.REGION_COLOR) brush_default = win32gui.SelectObject(hdc, brush) pen_default = win32gui.SelectObject(hdc, pen) win32gui.Rectangle(hdc, *self._selection) win32gui.SelectObject(hdc, pen_default) win32gui.SelectObject(hdc, brush_default) win32gui.EndPaint(hwnd, paint) return 0
def draw_ellipse(cls, region: Region, color: RGB = None) -> None: """Draws a colored ellipse around given region Args: region (Region): [description] color (RGB, optional): [description]. Defaults to None. """ if not color: color = RGB(0, 255, 0) dc = win32gui.GetDC(0) pen = win32gui.CreatePen(win32con.PS_SOLID, 2, color.to_color_ref()) brush = win32gui.CreateBrushIndirect({ 'Style': win32con.BS_NULL, 'Color': -1, 'Hatch': win32con.HS_DIAGCROSS }) win32gui.SelectObject(dc, pen) win32gui.SelectObject(dc, brush) win32gui.Ellipse(dc, *region.to_tuple()) win32gui.DeleteObject(pen) win32gui.DeleteObject(brush) win32gui.DeleteDC(dc)
def _thread_function(x, y, w, h, delay): [x, y, w, h] = map(int, [x, y, w, h]) delay = float(delay) # Получим контекст всех дисплев или всего рабочего стола: #scr_hdc = win32gui.GetDC(0) scr_hdc = win32gui.CreateDC('DISPLAY', None, None) mem_hdc = win32gui.CreateCompatibleDC( scr_hdc ) # New context of memory device. This one is compatible with 'scr_hdc' new_bitmap_h = win32gui.CreateCompatibleBitmap(scr_hdc, w + 2, h + 2) win32gui.SelectObject( mem_hdc, new_bitmap_h ) # Returns 'old_bitmap_h'. It will be deleted automatically. # Сохраняем рамочку в 1 пиксель (она вокруг области (x,y,w,h)): _cp_boundary(mem_hdc, 0, 0, scr_hdc, x - 1, y - 1, w + 2, h + 2) # Рисуем подсветку области: # brush = win32gui.CreateSolidBrush(win32api.RGB(255,0,0)) win32gui.SelectObject(scr_hdc, win32gui.GetStockObject(win32con.NULL_BRUSH)) pen = win32gui.CreatePen(win32con.PS_DOT, 1, win32api.RGB(148, 0, 0)) win32gui.SelectObject(scr_hdc, pen) for i in range(2): win32gui.Rectangle(scr_hdc, x - 1, y - 1, x + w + 1, y + h + 1) # Восстаналиваема рамочку: time.sleep(delay) _cp_boundary(scr_hdc, x - 1, y - 1, mem_hdc, 0, 0, w + 2, h + 2) #win32gui.ReleaseDC(scr_hdc, 0) win32gui.DeleteDC(scr_hdc) win32gui.DeleteDC(mem_hdc) win32gui.DeleteObject(new_bitmap_h)
def drawRect(pos, pred, colors): hwnd = win32gui.GetDesktopWindow() # 定义框颜色 hPen = win32gui.CreatePen(win32con.PS_SOLID, 3, win32api.RGB(colors[pred][0], colors[pred][1], colors[pred][2])) win32gui.InvalidateRect(hwnd, None, True) win32gui.UpdateWindow(hwnd) win32gui.RedrawWindow(hwnd, None, None, win32con.RDW_FRAME | win32con.RDW_INVALIDATE | win32con.RDW_UPDATENOW | win32con.RDW_ALLCHILDREN) # 根据窗口句柄获取窗口的设备上下文DC(Divice Context) hwndDC = win32gui.GetDC(hwnd) win32gui.SelectObject(hwndDC, hPen) # 定义透明画刷,这个很重要! hbrush = win32gui.GetStockObject(win32con.NULL_BRUSH) prebrush = win32gui.SelectObject(hwndDC, hbrush) # 左上到右下的坐标 win32gui.Rectangle(hwndDC, pos[0] - 240, pos[1] - 135, pos[0] + 240, pos[1] + 135) win32gui.SaveDC(hwndDC) win32gui.SelectObject(hwndDC, prebrush) # 回收资源 win32gui.DeleteObject(hPen) win32gui.DeleteObject(hbrush) win32gui.DeleteObject(prebrush) win32gui.ReleaseDC(hwnd, hwndDC)
def drawSoldiers(hDc, dataContainer, globalLock, cX, cY, lineWidth=1): """ win32gui.Rectangle(hDc, left, top, right, bottom) draw the box esp and the minimap """ globalLock.acquire() viewTransform = dataContainer.viewMatrix viewOrigin = dataContainer.viewOrigin viewForwardVec = dataContainer.viewForwardVec fovY = dataContainer.fovY fovX = dataContainer.fovX # i'm using the old bf3 worldToScreen calculation, so do not need the aspect ratio any more #aspect = dataContainer.aspectRatio globalLock.release() projM = getProjectionMatrixBF3(0.06, 10000.0, fovX, fovY) # ============== initialize the minimap ================ centerX, centerY = 200, 200 boundaryX, boundaryY = 160, 160 top, bottom = centerY - boundaryY, centerY + boundaryY left, right = centerX - boundaryX, centerX + boundaryX hPen = win32gui.CreatePen(win32con.PS_SOLID, 2, COLOR_BLUE) win32gui.SelectObject(hDc, hPen) win32gui.Rectangle(hDc, left, top, right, bottom) drawCrossHair(hDc, centerX, centerY, size=159, lineWidth=2, color=COLOR_BLUE) # ====================================================== # the consumer starts up - consuming n soldier objects at a time # n equals to the approximate size of the queue at that point for i in range(dataContainer.soldiers.qsize()): soldier = dataContainer.soldiers.get() # strictly speaking the soldier object can not be invalid (due to the producer-consumer # model), but just to be on the safe side... if not soldier.isValid(): continue distanceToViewOrigin = viewOrigin.distanceTo(soldier.posVec4) # visible enemy footman: Green color = COLOR_RED if soldier.occluded else COLOR_GREEN if soldier.isVehicle: hPen = win32gui.CreatePen(win32con.PS_SOLID, 2, COLOR_YELLOW) else: hPen = win32gui.CreatePen(win32con.PS_SOLID, lineWidth, color) win32gui.SelectObject(hDc, hPen) # here is the same logic as in BF3, applies to other MVP transformation as well posV = soldier.posVec4.multToMat(viewTransform) posVP = posV.multToMat(projM) if abs(posVP.w) > 0.001 and posVP.z <= 0: # ============== draw soldier box esp =============== # important! this is different from BF3 (d3d)!! scrX = int(cX * (1 + posVP.x / posVP.w)) scrY = int(cY * (1 - posVP.y / posVP.w)) # draw text text = "%d(%d)" % (int(distanceToViewOrigin), int(soldier.health)) win32gui.DrawText(hDc, text, len(text), (scrX, scrY, scrX + 68, scrY + 14), win32con.DT_TOP | win32con.DT_LEFT) # calculate the esp box size! # the reason I don't use the calculation is the scope will disturb the esp box if soldier.isVehicle: w, h = 6, 6 win32gui.Rectangle(hDc, scrX - w / 2, scrY - h, scrX + w / 2, scrY) else: w, h = 4, 4 #getWidthHeight(distanceToViewOrigin, soldier.stance) win32gui.Rectangle(hDc, scrX - w / 2, scrY - h, scrX + w / 2, scrY) # =================================================== if posV.w > 0.001: # =========== draw soldier minimap spot =========== # calculate the planar coord while compensate for the viewing angle dx = posV.x / posV.w cosA = viewForwardVec.dotProduct( vector.Vector4(viewForwardVec.x, 0.0, viewForwardVec.z, 0.0).normalize()) dy = posV.z / posV.w / abs(cosA) # limit the drawing to the defined minimap region dx = int(dx / 1.0 + centerX) dy = int(dy / 1.0 + centerY) if dx < left: dx = left if dx > right: dx = right if dy < top: dy = top if dy > bottom: dy = bottom # draw spot pColor = COLOR_RED if soldier.occluded else COLOR_GREEN hPen = win32gui.CreatePen(win32con.PS_SOLID, 2, pColor) win32gui.SelectObject(hDc, hPen) win32gui.Rectangle(hDc, dx, dy, dx + 2, dy + 2)
if state_switch < 0: counttt = 512 else: hWnd = win32gui.GetForegroundWindow() counttt = 512 if win32gui.GetWindowText(hWnd): print(win32gui.GetWindowText(hWnd)) program_list.append(win32gui.GetWindowText(hWnd)) del program_list[0] print(program_list) left, top, xx, yy = win32gui.GetWindowRect(hWnd) gui_dc = win32gui.GetDC(0) red = win32api.RGB(255, 0, 0) newpen = win32gui.CreatePen(win32con.PS_SOLID, 3, win32api.RGB(255, 0, 0)) prevpen = win32gui.SelectObject(gui_dc, newpen) print(left, top, xx, yy) offset = 5 win32gui.MoveToEx(gui_dc, left + offset, top) win32gui.LineTo(gui_dc, xx - offset, top) win32gui.LineTo(gui_dc, xx - offset, yy - offset) win32gui.LineTo(gui_dc, left + offset, yy - offset) win32gui.LineTo(gui_dc, left + offset, top) win32gui.ReleaseDC(hWnd, gui_dc) frame[:] = (49, 52, 49) hwndMain2 = win32gui.FindWindow(None, WINDOW_NAME)
import win32gui import win32con import win32ui hWnd = win32gui.GetDesktopWindow() # Retrieves a handle to the desktop window. The desktop window covers the entire screen. # The desktop window is the area on top of which other windows are painted. hdc = win32gui.GetDC(hWnd) #win32gui.GetDC(None) # A handle to the window whose DC is to be retrieved. If this value is NULL, GetDC # retrieves the DC for the entire screen. red = win32api.RGB(255, 0, 0) win32gui.SetPixel(hdc, 0, 0, red) # (0, 0)에 빨간 점 그리기 MyPen = win32gui.CreatePen(win32con.PS_SOLID, 5, win32api.RGB(0,0,255)); OldPen = win32gui.SelectObject(hdc, MyPen); win32gui.Rectangle(hdc, 50, 50, 100, 100) # (50, 50, 100, 100)에 파란 선으로 사각형 그리기 win32gui.SelectObject(hdc, OldPen); win32gui.DeleteObject(MyPen); # 폰트 만들기 font_spec = {'name':'Arial', 'height':42, 'weight':30} font = win32ui.CreateFont(font_spec) #lf = win32gui.LOGFONT() #lf.lfFaceName = "Times New Roman" #lf.lfHeight = 100 #lf.lfWeight = win32con.FW_NORMAL #hf = win32gui.CreateFontIndirect(lf)
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)
def drawSoldiers(hDc, dataContainer, globalLock): # ============== initialize the minimap =============== centerX, centerY = 230, 530 boundaryX, boundaryY = 230, 230 top, bottom = centerY - boundaryY, centerY + boundaryY left, right = centerX - boundaryX, centerX + boundaryX hPen = win32gui.CreatePen(win32con.PS_SOLID, 2, COLOR_BLUE) win32gui.SelectObject(hDc, hPen) win32gui.Rectangle(hDc, left, top, right, bottom) drawCrossHair(hDc, centerX, centerY, size=230, lineWidth=2, color=COLOR_BLUE) # ===================================================== # ============== initialize the offview esp ================ sizeX, sizeY = 230, 135 hPenESP = win32gui.CreatePen(win32con.PS_SOLID, 1, COLOR_RED) hPenRect = win32gui.CreatePen(win32con.PS_SOLID, 2, COLOR_BLUE) win32gui.SelectObject(hDc, hPenRect) win32gui.Rectangle(hDc, 0, 0, 460, 270) drawCrossHair(hDc, 230, 135, size=5, lineWidth=2, color=COLOR_BLUE) # ========================================================== if dataContainer.isInGame != 0x4000: return # get the view properties globalLock.acquire() viewOrigin = dataContainer.viewOrigin.copy() viewAxisX = dataContainer.viewAxisX.copy() viewAxisY = dataContainer.viewAxisY.copy() viewAxisZ = dataContainer.viewAxisZ.copy() fovX = dataContainer.fovX fovY = dataContainer.fovY globalLock.release() win32gui.SelectObject(hDc, hPenESP) for i in range(dataContainer.soldiers.qsize()): soldier = dataContainer.soldiers.get() if not soldier.isValid(): continue headPos = soldier.posVec4.copy() headPos.z += 60.0 distance = (headPos - viewOrigin).length()/10 feetCoords = worldToScreen(fovX, fovY, sizeX, sizeY, viewAxisX, viewAxisY, viewAxisZ, viewOrigin, soldier.posVec4) if not feetCoords: continue headCoords = worldToScreen(fovX, fovY, sizeX, sizeY, viewAxisX, viewAxisY, viewAxisZ, viewOrigin, headPos) if not headCoords: continue feetX, feetY, miniX, miniY = feetCoords headX, headY, _p, _q = headCoords height = headY - feetY width = height / 3 # esp win32gui.Rectangle(hDc, headX-width/2, headY, feetX+width/2, feetY) # mini map dx = miniX + centerX dy = miniY + centerY if dx < left: dx = left if dx > right:dx = right if dy < top : dy = top if dy > bottom:dy = bottom win32gui.Rectangle(hDc, dx, dy, dx+4, dy+4)
def appendFrameRectToWindow(hW, x, y, w, h): hDc = win32gui.GetWindowDC(hW) hPen = win32gui.CreatePen(win32con.PS_SOLID, 10, win32api.RGB(255, 0, 255)) win32gui.FrameRect(hDc, (x, y, x + w, y + h), hPen)