Пример #1
0
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
0
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)
Пример #3
0
def grab_im():
    while True:
        cursor_current_x, cursor_current_y = 0, 0
        crop_im = False
        win_DC = win32gui.GetDC(0)
        cursor_origin_x, cursor_origin_y = win32gui.GetCursorPos()
        full_image = ImageGrab.grab(bbox=(0, 0, win32api.GetSystemMetrics(0),
                                          win32api.GetSystemMetrics(1)))

        while win32api.GetAsyncKeyState(win32con.VK_CONTROL) < 0:
            if not crop_im:
                crop_im = True
            cursor_current_x, cursor_current_y = win32gui.GetCursorPos()
            win32gui.MoveToEx(win_DC, cursor_origin_x, cursor_origin_y)
            win32gui.LineTo(win_DC, cursor_origin_x, cursor_current_y)
            win32gui.MoveToEx(win_DC, cursor_origin_x, cursor_current_y)
            win32gui.LineTo(win_DC, cursor_current_x, cursor_current_y)
            win32gui.MoveToEx(win_DC, cursor_current_x, cursor_current_y)
            win32gui.LineTo(win_DC, cursor_current_x, cursor_origin_y)
            win32gui.MoveToEx(win_DC, cursor_current_x, cursor_origin_y)
            win32gui.LineTo(win_DC, cursor_origin_x, cursor_origin_y)

        if crop_im:
            cropped_image = full_image.crop(
                (min(cursor_current_x,
                     cursor_origin_x), min(cursor_current_y, cursor_origin_y),
                 max(cursor_current_x,
                     cursor_origin_x), max(cursor_current_y, cursor_origin_y)))
            return cropped_image
        sleep(.01)
Пример #4
0
def wndProc(hWnd, message, wParam, lParam):
    if not hasattr(wndProc, 'cxClient'):
        wndProc.cxClient = 0
        wndProc.cyClient = 0

    if message == win32con.WM_SIZE:
        wndProc.cxClient = win32gui.LOWORD(lParam)  # 附加参数的低位字保存窗口的宽度
        wndProc.cyClient = win32gui.HIWORD(lParam)  # 附加参数的高位字保存窗口的高度

    if message == win32con.WM_PAINT:
        hdc, paintStruct = win32gui.BeginPaint(hWnd)  # 获取窗口的dc和窗口客户区所需要的信息的结构
        win32gui.MoveToEx(hdc, 0, int(wndProc.cyClient /
                                      2))  # 移动到直线的起始点,这里比win32 API少了最后一个参数
        win32gui.LineTo(hdc, wndProc.cxClient,
                        int(wndProc.cyClient / 2))  # 画出直线
        vertices = list()  # 定义一个列表用来存储点,形式为[x,y]的形式
        point = list()  # 定义一个列表用来存储一系列作图的点
        for i in range(NUM):
            vertices = []
            vertices.append(int(i * wndProc.cxClient / NUM))  # 计算出x坐标
            vertices.append(
                int(wndProc.cyClient / 2 *
                    (1 - math.sin(2 * math.pi * i / NUM))))  # 计算出y坐标
            point.append(tuple(vertices))  # 将点添加到列表当中
        win32gui.Polyline(hdc, point)  # 画出正弦图像
        win32gui.EndPaint(hWnd, paintStruct)  # 关闭dc
        return 0

    if message == win32con.WM_DESTROY:
        win32gui.PostQuitMessage(0)  # 发送消息,退出窗口的进程
        return 0
    else:
        return win32gui.DefWindowProc(hWnd, message, wParam,
                                      lParam)  # 其他消息路由给操作系统处理
Пример #5
0
 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))
Пример #6
0
def grab_screen():
    while True:  # Loop until return
        cursor_current_x, cursor_current_y = 0, 0  # Declare variable for future cursor
        crop_im = False  # Declare boolean for cropping later

        win_DC = win32gui.GetDC(0)  # Get device context
        cursor_origin_x, cursor_origin_y = win32gui.GetCursorPos(
        )  # Get cursor position
        full_image = ImageGrab.grab(bbox=(
            0,  # Capture entire screen
            0,
            win32api.GetSystemMetrics(0),
            win32api.GetSystemMetrics(1)))

        while win32api.GetAsyncKeyState(
                win32con.VK_CONTROL) < 0:  # While CTRL key is pressed
            if not crop_im:
                crop_im = True  # Set crop bool so crop branch is entered after

            cursor_current_x, cursor_current_y = win32gui.GetCursorPos(
            )  # Get current cursor position
            win32gui.MoveToEx(
                win_DC, cursor_origin_x,
                cursor_origin_y)  # Draw a box with original cursor
            win32gui.LineTo(
                win_DC, cursor_origin_x,
                cursor_current_y)  # and current cursor as opposite corners
            win32gui.MoveToEx(win_DC, cursor_origin_x, cursor_current_y)
            win32gui.LineTo(win_DC, cursor_current_x, cursor_current_y)
            win32gui.MoveToEx(win_DC, cursor_current_x, cursor_current_y)
            win32gui.LineTo(win_DC, cursor_current_x, cursor_origin_y)
            win32gui.MoveToEx(win_DC, cursor_current_x, cursor_origin_y)
            win32gui.LineTo(win_DC, cursor_origin_x, cursor_origin_y)

        if crop_im:  # Enter crop branch, crop to box size
            cropped_image = full_image.crop(
                (min(cursor_current_x,
                     cursor_origin_x), min(cursor_current_y, cursor_origin_y),
                 max(cursor_current_x,
                     cursor_origin_x), max(cursor_current_y, cursor_origin_y)))
            return cropped_image  # RETURN: cropped image
        sleep(.01)  # Sleep so it doesn't waste resources
Пример #7
0
def grab_im():
    """
    选择区域截图,返回截取的PIL图片
    """
    while True:
        cursor_current_x, cursor_current_y = 0, 0
        crop_im = False

        # 获取设备环境
        win_DC = win32gui.GetDC(0)
        # 获取鼠标位置
        cursor_origin_x, cursor_origin_y = win32gui.GetCursorPos()
        # 截取全屏
        full_image = ImageGrab.grab(bbox=(0, 0, win32api.GetSystemMetrics(0),
                                          win32api.GetSystemMetrics(1)))

        # 只有当检测到CTRL键被按下时才进行截
        while win32api.GetAsyncKeyState(win32con.VK_CONTROL) < 0:
            if not crop_im:
                crop_im = True

            # 获取当前鼠标位置
            cursor_current_x, cursor_current_y = win32gui.GetCursorPos()
            # 绘制矩形框
            win32gui.MoveToEx(win_DC, cursor_origin_x, cursor_origin_y)
            win32gui.LineTo(win_DC, cursor_origin_x, cursor_current_y)
            win32gui.MoveToEx(win_DC, cursor_origin_x, cursor_current_y)
            win32gui.LineTo(win_DC, cursor_current_x, cursor_current_y)
            win32gui.MoveToEx(win_DC, cursor_current_x, cursor_current_y)
            win32gui.LineTo(win_DC, cursor_current_x, cursor_origin_y)
            win32gui.MoveToEx(win_DC, cursor_current_x, cursor_origin_y)
            win32gui.LineTo(win_DC, cursor_origin_x, cursor_origin_y)

        # 根据矩形框裁剪
        if crop_im:
            cropped_image = full_image.crop(
                (min(cursor_current_x,
                     cursor_origin_x), min(cursor_current_y, cursor_origin_y),
                 max(cursor_current_x,
                     cursor_origin_x), max(cursor_current_y, cursor_origin_y)))
            return cropped_image
        sleep(.01)
                    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)

        if run_button == 0:
            run_button2 = 0
            hwndMain = win32gui.FindWindow(None, titlee)
            # hwndMain = win32gui.GetForegroundWindow()
            left2, top2, x22, y22 = win32gui.GetWindowRect(hwndMain)
            if run_button3 == 0: