Beispiel #1
0
    def _win_message(self, hWnd, message, wParam, lParam):
        if message == win32_contants.WM_PAINT:
            device_context_handle, paintStruct = win32gui.BeginPaint(hWnd)
            dpiScale = ctypes.windll.gdi32.GetDeviceCaps(
                device_context_handle, win32_contants.LOGPIXELSX) / 60.0
            fontSize = 14

            # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
            lf = win32gui.LOGFONT()
            lf.lfFaceName = "Times New Roman"
            # lf.lfHeight = int(round(dpiScale * fontSize))
            lf.lfHeight = 20
            lf.lfWeight = 0
            # Use nonantialiased to remove the white edges around the text.
            lf.lfQuality = win32con.NONANTIALIASED_QUALITY
            hf = win32gui.CreateFontIndirect(lf)
            win32gui.SetTextColor(device_context_handle,
                                  win32_color(self.font_color))
            win32gui.SelectObject(device_context_handle, hf)
            self._draw(device_context_handle)
            win32gui.EndPaint(hWnd, paintStruct)
            return 0
        elif message == win32_contants.WM_DESTROY:
            win32gui.PostQuitMessage(0)
            return 0
        else:
            return ctypes.windll.user32.DefWindowProcW(hWnd, message, wParam,
                                                       lParam)
 def BGWndProc(self,hwnd,msg,wParam,lParam):
     if msg == win32con.WM_PAINT:
         #print('BG painting...%d...'%wParam)
         hdc,ps = win32gui.BeginPaint(hwnd)
         rect = win32gui.GetClientRect(hwnd)
 #        win32gui.Rectangle(hdc,min(xc),min(yc),max(xc),max(yc))
 #        win32gui.Ellipse(hdc,300+wParam,550,400+wParam,650)
         DFW.OnChange(mode='RandomMove')
         
         #self.hdcbuffer = win32gui.CreateCompatibleDC(hdc)
         #hBitMap = win32gui.CreateCompatibleBitmap(hdc, 1920, 1080)
         ###win32gui.ReleaseDC(hwnd, hdc)
         #win32gui.SelectObject(self.hdcbuffer, hBitMap)
         #win32gui.PatBlt(self.hdcbuffer, 0, 0, 1920, 1080, win32con.WHITENESS)
         
         #win32gui.SetBkMode(hdc,win32con.TRANSPARENT)
         for index in range(len(DFW.Words)):
             rect = (int(DFW.Coors[index][0]),int(DFW.Coors[index][1]),1920,1080)
             win32gui.DrawText(hdc,'%s,%d'%(DFW.Words[index],wParam),
                 len('%s'%(DFW.Words[index])),rect,win32con.DT_SINGLELINE|win32con.DT_TOP|win32con.DT_LEFT)
         #win32gui.BitBlt(hdc, 0, 0, 1920, 1080, self.hdcbuffer, 0, 0, win32con.SRCCOPY )
         win32gui.EndPaint(hwnd,ps)
     elif msg == win32con.WM_DESTROY:  
         win32gui.PostQuitMessage(0)
     elif msg == win32con.WM_TIMER:
         #print("BG TIMER TRIGGERED",wParam)
         win32gui.InvalidateRect(hwnd,None,True)
         win32gui.UpdateWindow(hwnd)
     else:
         pass
         #print('BG:其他信息:',msg)
     return win32gui.DefWindowProc(hwnd,msg,wParam,lParam)  
Beispiel #3
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
Beispiel #4
0
def wndProc(hWnd, message, wParam, lParam):
    if message == win32con.WM_PAINT:
        hDC, paintStruct = win32gui.BeginPaint(hWnd)

        rect = win32gui.GetClientRect(hWnd)
        win32gui.DrawText(
            hDC,
            'Hello send by Python via Win32!',
            -1,
            rect,
            win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER)

        win32gui.EndPaint(hWnd, paintStruct)
        return 0

    elif message == win32con.WM_DESTROY:
        print('Being destroyed')
        win32gui.PostQuitMessage(0)
        return 0
    elif message == FullGenMessage:
        print("Founded new message from FullGen")
        print(wParam)
        print(lParam)
        return 0
    else:
        return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Beispiel #5
0
def OnPaint_2(hwnd, msg, wp, lp):
    dc, ps = win32gui.BeginPaint(hwnd)
    win32gui.SetGraphicsMode(dc, win32con.GM_ADVANCED)
    l, t, r, b = win32gui.GetClientRect(hwnd)

    for x in range(25):
        vertices = (
            {'x': int(random.random() * r),
             'y': int(random.random() * b),
             'Red': int(random.random() * 0xff00),
             'Green': 0,
             'Blue': 0,
             'Alpha': 0},
            {'x': int(random.random() * r),
             'y': int(random.random() * b),
             'Red': 0,
             'Green': int(random.random() * 0xff00),
             'Blue': 0,
             'Alpha': 0},
            {'x': int(random.random() * r),
             'y': int(random.random() * b),
             'Red': 0,
             'Green': 0,
             'Blue': int(random.random() * 0xff00),
             'Alpha': 0},
        )
        mesh = ((0, 1, 2),)
        win32gui.GradientFill(
            dc, vertices, mesh, win32con.GRADIENT_FILL_TRIANGLE)
    win32gui.EndPaint(hwnd, ps)
    return 0
Beispiel #6
0
 def wndProc(self, hwnd, msg, wParam, lParam):
     """
     消息处理
     :param hwnd:
     :param msg:
     :param wParam:
     :param lParam:
     :return:
     """
     if msg == win32con.WM_PAINT:
         hdc, ps = win32gui.BeginPaint(hwnd)
         rect = win32gui.GetClientRect(hwnd)
         win32gui.DrawText(
             hdc, 'GUI Python', len('GUI Python'), rect,
             win32con.DT_SINGLELINE | win32con.DT_CENTER
             | win32con.DT_VCENTER)
         win32gui.EndPaint(hwnd, ps)
     if msg == win32con.WM_CREATE:
         print('message: WM_CREATE')
     if msg == win32con.WM_SIZE:
         print('message: WM_SIZE')
     if msg == win32con.WM_PAINT:
         print('message: WM_PAINT')
     if msg == 1280:
         print("message: 1280")
     if msg == win32con.WM_CLOSE:
         print('message: WM_CLOSE')
     if msg == win32con.WM_DESTROY:
         print('message: WM_DESTROY')
         win32gui.PostQuitMessage(0)
     return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
 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
Beispiel #8
0
def onPaint(hwnd, msg, wp, lp):
    hDc, ps = win32gui.BeginPaint(hwnd)
    win32gui.SetGraphicsMode(hDc, win32con.GM_ADVANCED)

    codghostdrawing.drawSoldiers(hDc, container, globalLock)

    win32gui.EndPaint(hwnd, ps)
    return 0
Beispiel #9
0
def WndProc(hwnd, msg, wParam, lParam):
    if msg == WM_PAINT:
        hdc, ps = win32gui.BeginPaint(hwnd)
        rect = win32gui.GetClientRect(hwnd)
        win32gui.DrawText(hdc, 'GUI Python', len('GUI Python'), rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER)
        win32gui.EndPaint(hwnd, ps)
    if msg == WM_DESTROY:
        win32gui.PostQuitMessage(0)
    return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
Beispiel #10
0
def wndProc(hWnd, message, wParam, lParam):
    global data

    if message == win32con.WM_PAINT:
        hdc, paintStruct = win32gui.BeginPaint(hWnd)

        dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
        fontSize = 80

        # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
        lf = win32gui.LOGFONT()
        lf.lfFaceName = "Times New Roman"
        lf.lfHeight = int(round(dpiScale * fontSize))
        #lf.lfWeight = 150
        # Use nonantialiased to remove the white edges around the text.
        # lf.lfQuality = win32con.NONANTIALIASED_QUALITY
        hf = win32gui.CreateFontIndirect(lf)
        win32gui.SelectObject(hdc, hf)

        rect = win32gui.GetClientRect(hWnd)
        # http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx
        if not loaded:
            win32gui.DrawText(
                hdc, 'Loading Neural Net...', -1, rect,
                win32con.DT_CENTER | win32con.DT_NOCLIP
                | win32con.DT_SINGLELINE | win32con.DT_VCENTER)

        color = win32api.RGB(0, 0, 255)
        color2 = win32api.RGB(255, 255, 0)
        brush = win32gui.CreateSolidBrush(color)
        fontSize = 12
        lf = win32gui.LOGFONT()
        lf.lfFaceName = 'Times New Roman'
        lf.lfHeight = int(round(dpiScale * fontSize))
        lf.lfQuality = win32con.NONANTIALIASED_QUALITY
        hf = win32gui.CreateFontIndirect(lf)
        win32gui.SelectObject(hdc, hf)
        win32gui.SetTextColor(hdc, color2)

        for minion in data:
            win32gui.DrawText(
                hdc, minion['class'] + ' ' + str(int(minion['score'] * 100)),
                -1, minion['location'], win32con.DT_BOTTOM
                | win32con.DT_SINGLELINE | win32con.DT_NOCLIP)
            win32gui.FrameRect(hdc, minion['location'], brush)

        win32gui.EndPaint(hWnd, paintStruct)
        return 0

    elif message == win32con.WM_DESTROY:
        print('Closing the window.')
        win32gui.PostQuitMessage(0)
        return 0

    else:
        return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Beispiel #11
0
def onPaint(hwnd, msg, wp, lp):
    hDc, ps = win32gui.BeginPaint(hwnd)
    win32gui.SetGraphicsMode(hDc, win32con.GM_ADVANCED)
    bf4drawing.setTextColor(hDc)

    bf4drawing.drawCrossHair(hDc, centerX, centerY, size=10)
    bf4drawing.drawSoldiers(hDc, dataContainer, globalLock, centerX, centerY)

    win32gui.EndPaint(hwnd, ps)
    return 0
Beispiel #12
0
def OnPaint(hwnd, msg, wp, lp):
	global dx
	dc, ps=win32gui.BeginPaint(hwnd)
	win32gui.SetGraphicsMode(dc, win32con.GM_ADVANCED)
	l,t,r,b=win32gui.GetClientRect(hwnd)
	br=win32gui.CreateSolidBrush(win32api.RGB(0,0,255))
	win32gui.SelectObject(dc, br)
	win32gui.FillRect(dc,(200+dx,200+dx,100+dx,100+dx),br)
	dx=(dx+10)%100
	win32gui.EndPaint(hwnd, ps)
	return 0
Beispiel #13
0
    def Render(hWnd):
        hDC, paintStruct = win32gui.BeginPaint(hWnd)

        rect = win32gui.GetClientRect(hWnd)
        win32gui.DrawText(
            hDC,
            'Hello send by Python via Win32!',
            -1,
            rect,
            win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER)

        win32gui.EndPaint(hWnd, paintStruct)
        pass
Beispiel #14
0
def wndProc(hWnd, message, wParam, lParam):
    global hdc
    if message == win32con.WM_PAINT:
        hdc, paintStruct = win32gui.BeginPaint(hWnd)
        debugRender(hWnd, hdc, paintStruct)

        win32gui.EndPaint(hWnd, paintStruct)
        return 0

    elif message == win32con.WM_DESTROY:
        print('Closing the window.')
        win32gui.PostQuitMessage(0)
        return 0

    else:
        return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Beispiel #15
0
 def WndProc(self, hwnd, msg, wParam, lParam):
     if msg == win32con.WM_PAINT:
         print('WM_PAINT')
         hdc, ps = win32gui.BeginPaint(hwnd)
         rect = win32gui.GetClientRect(hwnd)
         win32gui.DrawText(
             hdc, 'GUI Python', len('GUI Python'), rect,
             win32con.DT_SINGLELINE | win32con.DT_CENTER
             | win32con.DT_VCENTER)
         win32gui.EndPaint(hwnd, ps)
     if msg == win32con.WM_DESTROY:
         print('WM_DESTROY')
         win32gui.PostQuitMessage(0)
     if msg == win32con.WM_DEVICECHANGE:
         print('WM_DEVICECHANGE')
         self.hotplugCallbackWin(hwnd, msg, wParam, lParam)
     return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
Beispiel #16
0
    def OnPaint(self, hWnd, msg, wparam, lparam):
        dc, ps = win32gui.BeginPaint(hWnd)
        wndrect = win32gui.GetClientRect(hWnd)
        wndwidth = wndrect[2] - wndrect[0]
        wndheight = wndrect[3] - wndrect[1]
        if os.path.isfile(FILENAME):
            hBitmap = win32gui.LoadImage(0, FILENAME, win32con.IMAGE_BITMAP, 0,
                                         0, win32con.LR_LOADFROMFILE)
            hdcBitmap = win32gui.CreateCompatibleDC(dc)
            hOldBitmap = win32gui.SelectObject(hdcBitmap, hBitmap)
            bminfo = win32gui.GetObject(hBitmap)
            win32gui.SetStretchBltMode(dc, win32con.COLORONCOLOR)
            win32gui.StretchBlt(dc, 0, 0, wndwidth, wndheight, hdcBitmap, 0, 0,
                                bminfo.bmWidth, bminfo.bmHeight,
                                win32con.SRCCOPY)
            win32gui.SelectObject(hdcBitmap, hOldBitmap)

        win32gui.EndPaint(hWnd, ps)
        return 0
Beispiel #17
0
def wndProc(hWnd, message, wParam, lParam):
    if message == win32con.WM_PAINT:
        hDC, paintStruct = win32gui.BeginPaint(hWnd)
        rect = win32gui.GetClientRect(hWnd)
        win32gui.DrawText(
            hDC, 'Hello send by Python via Win32!', -1, rect,
            win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER)

        win32gui.EndPaint(hWnd, paintStruct)
        return 0
    elif message == win32con.WM_DESTROY:
        win32gui.PostQuitMessage(0)
        return 0
    elif message == FullGenMessage:
        connection.set("wParam", str(wParam))
        connection.set("lParam", str(lParam))
        return 0
    else:
        return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Beispiel #18
0
def WndProc(hwnd, msg, wParam, lParam):

    if msg == WM_PAINT:
        hdc, ps = win32gui.BeginPaint(hwnd)
        rect = win32gui.GetClientRect(hwnd)
        _str = u'请把【xlsx】文件拖拽到这!'
        win32gui.DrawText(hdc, _str,
                          len(_str) * 2 - 4, rect,
                          DT_SINGLELINE | DT_CENTER | DT_VCENTER)
        win32gui.EndPaint(hwnd, ps)
        win32gui.DragAcceptFiles(hwnd, 1)
    elif msg == WM_DESTROY:
        win32gui.PostQuitMessage(0)
    elif msg == WM_DROPFILES:
        hDropInfo = wParam
        filescount = win32api.DragQueryFile(hDropInfo)
        for i in range(filescount):
            filename = win32api.DragQueryFile(hDropInfo, i)
            fileHandler(filename)
        win32api.DragFinish(hDropInfo)

    return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
Beispiel #19
0
def OnPaint(hwnd, msg, wp, lp):
    """Windows needs repainting"""

    dc, ps = win32gui.BeginPaint(hwnd)

    #Draw red circle
    br = win32gui.CreateSolidBrush(win32api.RGB(255, 0, 0))
    win32gui.SelectObject(dc, br)
    win32gui.Ellipse(dc, 20, 20, 120, 120)

    #Draw green rectangle
    br = win32gui.CreateSolidBrush(win32api.RGB(0, 255, 0))
    win32gui.SelectObject(dc, br)
    win32gui.Rectangle(dc, 150, 20, 300, 120)

    #Draw blue triangle
    br = win32gui.CreateSolidBrush(win32api.RGB(0, 0, 255))
    win32gui.SelectObject(dc, br)
    win32gui.Polygon(dc, [(400, 20), (350, 120), (450, 120)])

    win32gui.EndPaint(hwnd, ps)
    return 0
Beispiel #20
0
 def _paint(self, window, message, w, l):
     """Draw the Labels on the Windows surface"""
     try:
         if not self.__init:
             return
         handle, paint = gui.BeginPaint(window)
         r = self.rectangle
         y, w, h = 0, r[2] - r[0], r[3] - r[1]
         for _, (text, image, color,
                 font) in sorted(self._labels.copy().items(),
                                 key=lambda k: k[0]):
             x = 0
             if image is not None:
                 x = self._draw_image(handle, paint, (0, y, w, h - y),
                                      image)
             box = (x, y, w, h - y)
             _y, _ = self._draw_text(handle, box, text, color, font)
             y += _y
         gui.EndPaint(window, paint)
         return 0
     except Exception as e:
         self._error = e
         return -1
    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 wndProc(hWnd, message, wParam, lParam):
    if message == win32con.WM_PAINT:
        hdc, paintStruct = win32gui.BeginPaint(hWnd)
        print 'windProc'
        dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
        fontSize = 80
        lf = win32gui.LOGFONT()
        lf.lfFaceName = "Times New Roman"
        lf.lfHeight = int(round(dpiScale * fontSize))
        hf = win32gui.CreateFontIndirect(lf)
        win32gui.SelectObject(hdc, hf)
        rect = win32gui.GetClientRect(hWnd)
        win32gui.DrawText(
            hdc, 'O', -1, rect, win32con.DT_CENTER | win32con.DT_NOCLIP
            | win32con.DT_SINGLELINE | win32con.DT_VCENTER)
        win32gui.EndPaint(hWnd, paintStruct)
        return 0
    elif message == win32con.WM_DESTROY:
        print 'Closing the window.'
        win32gui.PostQuitMessage(0)
        return 0
    else:
        return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Beispiel #23
0
def OnPaint_2(hwnd, msg, wp, lp):
    dc, ps = win32gui.BeginPaint(hwnd)
    win32gui.SetGraphicsMode(dc, win32con.GM_ADVANCED)
    l, t, r, b = win32gui.GetClientRect(hwnd)

    for x in range(25):
        vertices = (
            {
                "x": int(random.random() * r),
                "y": int(random.random() * b),
                "Red": int(random.random() * 0xFF00),
                "Green": 0,
                "Blue": 0,
                "Alpha": 0,
            },
            {
                "x": int(random.random() * r),
                "y": int(random.random() * b),
                "Red": 0,
                "Green": int(random.random() * 0xFF00),
                "Blue": 0,
                "Alpha": 0,
            },
            {
                "x": int(random.random() * r),
                "y": int(random.random() * b),
                "Red": 0,
                "Green": 0,
                "Blue": int(random.random() * 0xFF00),
                "Alpha": 0,
            },
        )
        mesh = ((0, 1, 2), )
        win32gui.GradientFill(dc, vertices, mesh,
                              win32con.GRADIENT_FILL_TRIANGLE)
    win32gui.EndPaint(hwnd, ps)
    return 0
Beispiel #24
0
    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 wndProc(hWnd, message, wParam, lParam):
    if message == win32con.WM_PAINT:
        hdc, paintStruct = win32gui.BeginPaint(hWnd)
        print 'windProc'
        dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
        fontSize = 80

        # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
        lf = win32gui.LOGFONT()
        lf.lfFaceName = "Times New Roman"
        lf.lfHeight = int(round(dpiScale * fontSize))
        #lf.lfWeight = 150
        # Use nonantialiased to remove the white edges around the text.
        # lf.lfQuality = win32con.NONANTIALIASED_QUALITY
        hf = win32gui.CreateFontIndirect(lf)
        win32gui.SelectObject(hdc, hf)

        rect = win32gui.GetClientRect(hWnd)
        # http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx
        win32gui.DrawText(
            hdc,
            'O',
            -1,
            rect,
            win32con.DT_CENTER | win32con.DT_NOCLIP | win32con.DT_SINGLELINE | win32con.DT_VCENTER
        )
        win32gui.EndPaint(hWnd, paintStruct)
        return 0

    elif message == win32con.WM_DESTROY:
        print 'Closing the window.'
        win32gui.PostQuitMessage(0)
        return 0

    else:
        return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Beispiel #26
0
    def wndProc(self, hWnd, message, wParam, lParam):

        if message == win32con.WM_PAINT:
            hDC, paintStruct = win32gui.BeginPaint(hWnd)
            folder_with_ico_file = 'share' if hasattr(sys,
                                                      'frozen') else 'windows'
            filename = os.path.join(os.path.dirname(sys.argv[0]),
                                    folder_with_ico_file, 'bleachbit.ico')
            flags = win32con.LR_LOADFROMFILE
            hIcon = win32gui.LoadImage(0, filename, win32con.IMAGE_ICON, 0, 0,
                                       flags)

            # Default icon size seems to be 32 pixels so we center the icon vertically.
            default_icon_size = 32
            icon_top_margin = self._splash_screen_height - 2 * (
                default_icon_size + 2)
            win32gui.DrawIcon(hDC, 0, icon_top_margin, hIcon)
            # win32gui.DrawIconEx(hDC, 0, 0, hIcon, 64, 64, 0, 0, win32con.DI_NORMAL)

            rect = win32gui.GetClientRect(hWnd)
            textmetrics = win32gui.GetTextMetrics(hDC)
            text_left_margin = 2 * default_icon_size
            text_rect = (text_left_margin,
                         (rect[3] - textmetrics['Height']) // 2, rect[2],
                         rect[3])
            win32gui.DrawText(hDC, _("BleachBit is starting...\n"), -1,
                              text_rect, win32con.DT_WORDBREAK)
            win32gui.EndPaint(hWnd, paintStruct)
            return 0

        elif message == win32con.WM_DESTROY:
            win32gui.PostQuitMessage(0)
            return 0

        else:
            return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Beispiel #27
0
    def wndProc(self, hWnd, message, wParam, lParam):

        if message == win32con.WM_PAINT:
            hdc, paintStruct = win32gui.BeginPaint(hWnd)

            # Font configuration
            dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
            fontSize = 10

            # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
            lf = win32gui.LOGFONT()
            lf.lfFaceName = "Tahoma"
            lf.lfHeight = int(round(dpiScale * fontSize))
            lf.lfWeight = 700  # bold
            lf.lfQuality = win32con.NONANTIALIASED_QUALITY  # Use nonantialiased to remove the white edges around the text.

            hf = win32gui.CreateFontIndirect(lf)

            win32gui.SelectObject(hdc, hf)

            br = win32gui.CreateSolidBrush(win32api.RGB(255, 0, 0))
            win32gui.SelectObject(hdc, br)

            # Update positions
            self.updatePositions()

            # Bars
            # Positions the bars
            if self.mounted:
                xc = self.axcm
                yc = self.aycm
            else:
                xc = self.axc
                yc = self.ayc

            r = self.aradius
            dr = self.awidth
            alpha = self.aangle

            #print(xc,yc)

            ## Text
            # Positions the text
            pleft = self.tleft
            ptop = self.ttop
            pright = self.tright
            pbottom = self.tbottom
            spc = self.tspc

            #print(pleft,ptop,pright,pbottom)
            if self.setup:
                sr = alpha
                rr = r
                for _ in range(2):
                    sr, rr = self.drawRightArc(hdc, (xc, yc), rr, dr, sr, 1.0,
                                               ColorCode.ORANGE)

                sl = alpha
                rl = r
                for _ in range(2):
                    sl, rl = self.drawLeftArc(hdc, (xc, yc), rl, dr, sl, 1.0,
                                              ColorCode.ORANGE)

                for i in range(50):
                    pos = (pleft, ptop + i * spc, pright, pbottom)
                    self.drawTextLabel(hdc, pos, ColorCode.ORANGE,
                                       'ExampleText')
                    self.drawTimerLabel(hdc, pos, ColorCode.ORANGE, float(i))

            else:
                idx = 0
                sr = alpha
                rr = r
                for idx, action in enumerate(self.rightArcToDraw):
                    sr, rr = self.drawRightArc(hdc, (xc, yc), rr, dr, sr,
                                               action.getPercentage(),
                                               action.color)

                sl = alpha
                rl = r
                for idx, action in enumerate(self.leftArcToDraw):
                    sl, rl = self.drawLeftArc(hdc, (xc, yc), rl, dr, sl,
                                              action.getPercentage(),
                                              action.color)

                for idx, group in enumerate(self.groupsToDraw):
                    pos = (pleft, ptop + idx * spc, pright, pbottom)
                    self.drawTextLabel(hdc, pos, group.color, group.labelText)
                    self.drawTimerLabel(hdc, pos, group.color, group.countdown)

                k = idx + 2
                for idx, action in enumerate(self.actionsToDraw):
                    if (idx + 1) in self.emptyLines: k = k + 1

                    pos = (pleft, ptop + (idx + k) * spc, pright, pbottom)
                    self.drawTextLabel(hdc, pos, action.color,
                                       action.labelText)
                    self.drawTimerLabel(hdc, pos, action.color,
                                        action.countdown)

                k = k + idx + 2
                for idx, equip in enumerate(self.equipmentToDraw):
                    #if (idx+1) in emptyLines : k=k+1

                    pos = (pleft, ptop + (idx + k) * spc, pright, pbottom)
                    self.drawTextLabel(hdc, pos, equip.color, equip.labelText)
                    self.drawTimerLabel(hdc, pos, equip.color, equip.countdown)

                win32gui.EndPaint(hWnd, paintStruct)
                return 0

        elif message == win32con.WM_DESTROY:
            win32gui.PostQuitMessage(0)
            return 0

        else:
            return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
        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)
Beispiel #29
0
        def __init__(self, agent_status, salt_status, check_status, mesh_status):
            self.agent_status = agent_status
            self.salt_status = salt_status
            self.check_status = check_status
            self.mesh_status = mesh_status
            self.icon = os.path.join(os.getcwd(), "onit.ico")
            win32gui.InitCommonControls()
            self.hinst = win32api.GetModuleHandle(None)
            className = "AgentStatus"
            message_map = {
                win32con.WM_DESTROY: self.OnDestroy,
            }
            wc = win32gui.WNDCLASS()
            wc.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
            try:
                wc.hIcon = win32gui.LoadImage(
                    self.hinst,
                    self.icon,
                    win32con.IMAGE_ICON,
                    0,
                    0,
                    win32con.LR_LOADFROMFILE,
                )
            except Exception:
                pass
            wc.lpfnWndProc = message_map
            wc.lpszClassName = className
            win32gui.RegisterClass(wc)
            style = win32con.WS_OVERLAPPEDWINDOW
            self.hwnd = win32gui.CreateWindow(
                className,
                "Tactical RMM",
                style,
                win32con.CW_USEDEFAULT,
                win32con.CW_USEDEFAULT,
                400,
                300,
                0,
                0,
                self.hinst,
                None,
            )

            win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)

            hDC, paintStruct = win32gui.BeginPaint(self.hwnd)
            rect = win32gui.GetClientRect(self.hwnd)
            win32gui.DrawText(
                hDC,
                f"Agent: {self.agent_status}",
                -1,
                (0, 0, 384, 201),
                win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER,
            )

            win32gui.DrawText(
                hDC,
                f"Check Runner: {self.check_status}",
                -1,
                (0, 0, 384, 241),
                win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER,
            )
            win32gui.DrawText(
                hDC,
                f"Salt Minion: {self.salt_status}",
                -1,
                (0, 0, 384, 281),
                win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER,
            )
            win32gui.DrawText(
                hDC,
                f"Mesh Agent: {self.mesh_status}",
                -1,
                (0, 0, 384, 321),
                win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER,
            )

            win32gui.EndPaint(self.hwnd, paintStruct)
            win32gui.UpdateWindow(self.hwnd)
Beispiel #30
0
        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)