Exemple #1
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)  # 其他消息路由给操作系统处理
Exemple #2
0
 def command(self, hwnd, msg, wparam, lparam):
     id = win32gui.LOWORD(wparam)
     self.execute_menu_option(id)
Exemple #3
0
	def callback(self, hwnd, msg, wparam, lparam):
		# Called when the user clicks an item.
		self.destroy_nothing()
		self.action_map[win32gui.LOWORD(wparam)].run()
		sys.exit(0)
Exemple #4
0
 def _command(klass, hwnd, msg, wparam, lparam):
     wid = win32gui.LOWORD(wparam)
     self = klass._instance[hwnd]
     self.choose(wid)
     return
Exemple #5
0
 def command(self, hwnd, msg, wparam, lparam):
     print("command--->")
     id = win32gui.LOWORD(wparam)
     self.execute_menu_option(id)
     print("<---command")
Exemple #6
0
    def command(self, hwnd, msg, wparam, lparam):

        if DEBUG: print(sys._getframe(0).f_code.co_name)

        id = win32gui.LOWORD(wparam)
        self.execute_menu_option(id)
Exemple #7
0
 def OnCommand(self, hwnd, msg, wparam, lparam):
     id = win32gui.LOWORD(wparam)
     self.menu_options[id](self)
Exemple #8
0
 def _commandCallback(self, hwnd, msg, wparam, lparam):
     try:
         callback = self._callbacks[win32gui.LOWORD(wparam)]
     except:
         return
     callback()
Exemple #9
0
 def command(self, window_id, msg, wparam, lparam):
     id = win32gui.LOWORD(wparam)
     if id == EXIT_COMMAND:
         self.destroy(window_id, msg, wparam, lparam)
     if id == OPEN_COMMAND:
         webbrowser.open(self.target_url)
Exemple #10
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)