我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用win32gui.RegisterWindowMessage()。
def TestObjectFromWindow(): # Check we can use ObjectFromLresult to get the COM object from the # HWND - see KB Q249232 # Locating the HWND is different than the KB says... hwnd = win32gui.FindWindow('IEFrame', None) for child_class in ['TabWindowClass', 'Shell DocObject View', 'Internet Explorer_Server']: hwnd = win32gui.FindWindowEx(hwnd, 0, child_class, None) # ack - not working for markh on vista with IE8 (or maybe it is the # lack of the 'accessibility' components mentioned in Q249232) # either way - not working! return # But here is the point - once you have an 'Internet Explorer_Server', # you can send a message and use ObjectFromLresult to get it back. msg = win32gui.RegisterWindowMessage("WM_HTML_GETOBJECT") rc, result = win32gui.SendMessageTimeout(hwnd, msg, 0, 0, win32con.SMTO_ABORTIFHUNG, 1000) ob = pythoncom.ObjectFromLresult(result, pythoncom.IID_IDispatch, 0) doc = Dispatch(ob) # just to prove it works, set the background color of the document. for color in "red green blue orange white".split(): doc.bgColor = color time.sleep(0.2)
def __init__(self): super(KeyCounter, self).__init__() self.HWND = None self.hook = pyHook.HookManager() self.FPS = 60 self.MSPF = int(round(1000.0 / self.FPS)) self.font = None self.tooltip = self.name # Private message to be used in THIS program ONLY self.MESSAGE = random.randint(win32con.WM_USER, 0x7FFF) self.__MESSAGE_TC = win32gui.RegisterWindowMessage('TaskbarCreated') self.__NOTIFY_ID = None self.MENU = None self.APP_NAME = u'{} {}'.format(self.name, self.version) self.MENU_FUNCS = { 'Quit': self.stop, } self.MENU_TEXTS = [self.APP_NAME, 'Quit', ][::-1] self.__last_text_extent = (0, 0) self.SICHECK_EVENT = None self.GUID = '76B80C3C-11AB-47CD-A124-BADB07F41DB8'
def __init__(self, netkeeper): msg_TaskbarRestart = win32gui.RegisterWindowMessage("NKService") message_map = { msg_TaskbarRestart: self.OnRestart, win32con.WM_DESTROY: self.OnDestroy, win32con.WM_COMMAND: self.OnCommand, win32con.WM_USER + 20: self.OnTaskbarNotify, } # ????? wndclass = win32gui.WNDCLASS() hinst = wndclass.hInstance = win32api.GetModuleHandle(None) wndclass.lpszClassName = "NetkeeperTrayIcon" wndclass.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW wndclass.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW) wndclass.hbrBackground = win32con.COLOR_WINDOW wndclass.lpfnWndProc = message_map try: classAtom = win32gui.RegisterClass(wndclass) except win32gui.error, err_info: if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS: raise style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(wndclass.lpszClassName, 'NetKeeper Service', style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self.netkeeper = netkeeper self._createIcon()
def __init__(self, icon, hover_text, menu_options, on_quit=None, default_menu_index=None, window_class_name=None, wnd=None,): self.icon = icon self.hover_text = hover_text self.on_quit = on_quit menu_options = menu_options + (('Quit', None, self.QUIT),) self._next_action_id = self.FIRST_ID self.menu_actions_by_id = set() self.menu_options = self._add_ids_to_menu_options(list(menu_options)) self.menu_actions_by_id = dict(self.menu_actions_by_id) del self._next_action_id self.wnd = wnd self.default_menu_index = (default_menu_index or 0) self.window_class_name = window_class_name or "SysTrayIconPy" message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart, win32con.WM_DESTROY: self.destroy, win32con.WM_COMMAND: self.command, win32con.WM_USER+20 : self.notify,} # Register the Window class. window_class = win32gui.WNDCLASS() hinst = window_class.hInstance = win32gui.GetModuleHandle(None) window_class.lpszClassName = self.window_class_name window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) window_class.hbrBackground = win32con.COLOR_WINDOW window_class.lpfnWndProc = message_map # could also specify a wndproc. classAtom = win32gui.RegisterClass(window_class) # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name, style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self.notify_id = None self.refresh_icon() win32gui.PumpMessages()
def __init__(self): msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarCreated"); message_map = { msg_TaskbarRestart: self.OnRestart, win32con.WM_DESTROY: self.OnDestroy, win32con.WM_COMMAND: self.OnCommand, win32con.WM_USER+20 : self.OnTaskbarNotify, } # Register the Window class. wc = win32gui.WNDCLASS() hinst = wc.hInstance = win32api.GetModuleHandle(None) wc.lpszClassName = "PythonTaskbarDemo" wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; wc.hCursor = win32api.LoadCursor( 0, win32con.IDC_ARROW ) wc.hbrBackground = win32con.COLOR_WINDOW wc.lpfnWndProc = message_map # could also specify a wndproc. # Don't blow up if class already registered to make testing easier try: classAtom = win32gui.RegisterClass(wc) except win32gui.error, err_info: if err_info.winerror!=winerror.ERROR_CLASS_ALREADY_EXISTS: raise # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow( wc.lpszClassName, "Taskbar Demo", style, \ 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \ 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self._DoCreateIcons()
def __init__(self): msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarCreated"); message_map = { msg_TaskbarRestart: self.OnRestart, win32con.WM_DESTROY: self.OnDestroy, win32con.WM_COMMAND: self.OnCommand, win32con.WM_USER+20 : self.OnTaskbarNotify, } # Register the Window class. wc = win32gui.WNDCLASS() hinst = wc.hInstance = win32api.GetModuleHandle(None) wc.lpszClassName = "PythonTaskbarDemo" wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; wc.hCursor = win32api.LoadCursor( 0, win32con.IDC_ARROW ) wc.hbrBackground = win32con.COLOR_WINDOW wc.lpfnWndProc = message_map # could also specify a wndproc. # Don't blow up if class already registered to make testing easier try: classAtom = win32gui.RegisterClass(wc) except win32gui.error as err_info: if err_info.winerror!=winerror.ERROR_CLASS_ALREADY_EXISTS: raise # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow( wc.lpszClassName, "Taskbar Demo", style, \ 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \ 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self._DoCreateIcons()
def __init__(self, icon, hover_text, menu_options, on_quit=None, default_menu_index=None, window_class_name=None, ): self.icon = icon self.hover_text = hover_text self.on_quit = on_quit menu_options = menu_options + (('Quit', None, self.QUIT),) self._next_action_id = self.FIRST_ID self.menu_actions_by_id = set() self.menu_options = self._add_ids_to_menu_options(list(menu_options)) self.menu_actions_by_id = dict(self.menu_actions_by_id) del self._next_action_id self.default_menu_index = (default_menu_index or 0) self.window_class_name = window_class_name or "SysTrayIconPy" message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart, win32con.WM_DESTROY: self.destroy, win32con.WM_COMMAND: self.command, win32con.WM_USER + 20: self.notify, } # Register the Window class. window_class = win32gui.WNDCLASS() hinst = window_class.hInstance = win32gui.GetModuleHandle(None) window_class.lpszClassName = self.window_class_name window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) window_class.hbrBackground = win32con.COLOR_WINDOW window_class.lpfnWndProc = message_map # could also specify a wndproc. classAtom = win32gui.RegisterClass(window_class) # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name, style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self.notify_id = None self.refresh_icon() win32gui.PumpMessages()