def MyWndProc(self, hwnd, msg, wParam, lParam): # Display what we've got. if PRINT_MESSAGES: print(msgdict.get(msg), msg, wParam, lParam) # Restore the old WndProc. Notice the use of win32api # instead of win32gui here. This is to avoid an error due to # not passing a callable object. if msg == win32con.WM_DESTROY: win32api.SetWindowLong(self.GetHandle(), win32con.GWL_WNDPROC, _oldWndProc) stopproc = False for cb, cbtrigger in CALLBACKS[self]: if cbtrigger(self, msg, wParam, lParam): if not cb(self, msg, wParam, lParam): stopproc = True break if stopproc: return # Pass all messages (in this case, yours may be different) on to # the original WndProc return win32gui.CallWindowProc(_oldWndProc, hwnd, msg, wParam, lParam)
def _onWndProcCallback(self, hwnd, msg, wParam, lParam): if msg in self.msg_func_dict: argcount = self.msg_func_dict[msg].__code__.co_argcount ret = None if argcount == 5: arg_vals = self.msg_func_dict[msg].__code__.co_varnames if arg_vals[0] == 'self': ret = self.msg_func_dict[msg](self.webview, hwnd, wParam, lParam) elif argcount == 4: ret = self.msg_func_dict[msg](self.webview, hwnd, wParam, lParam) elif argcount == 3: ret = self.msg_func_dict[msg](hwnd, wParam, lParam) elif argcount == 2: ret = self.msg_func_dict[msg](wParam, lParam) if ret != None: return ret if hasattr(self, 'onWndProcCallback'): ret = self.onWndProcCallback(hwnd=hwnd, msg=msg, wParam=wParam, lParam=lParam) if ret != None: return ret if msg == WinConst.WM_DESTROY: self.unhook_WndProc() return win32gui.CallWindowProc(self.oldWndProc, hwnd, msg, wParam, lParam)
def MyWndProc(hWnd, msg, wParam, lParam): #from the web!: WM_WTSSESSION_CHANGE is 0x02b1. if msg == 0x02b1: log.debug("Session state change!") elif msg == win32con.WM_DESTROY: # Restore the old WndProc log.debug("WM_DESTROY, restoring call handler") win32api.SetWindowLong(app_hwnd, win32con.GWL_WNDPROC, self.oldWndProc) elif msg == win32con.WM_COMMAND: log.debug("WM_COMMAND") elif msg == WM_TRAYICON: log.debug("WM_TRAYICON") if lParam == NIN_BALLOONSHOW: log.debug("NIN_BALLOONSHOW") if lParam == NIN_BALLOONHIDE: log.debug("NIN_BALLOONHIDE") self.balloon_click_callback = None elif lParam == NIN_BALLOONTIMEOUT: log.debug("NIN_BALLOONTIMEOUT") elif lParam == NIN_BALLOONUSERCLICK: log.info( "NIN_BALLOONUSERCLICK, balloon_click_callback=%s" % self.balloon_click_callback) if self.balloon_click_callback: self.balloon_click_callback() self.balloon_click_callback = None else: log.debug("unkown message") # Pass all messages to the original WndProc try: return win32gui.CallWindowProc(self.old_win32_proc, hWnd, msg, wParam, lParam) except Exception, e: log.error("error delegating call: %s", e)
def MyWndProc(self, hWnd, msg, wParam, lParam): assert hWnd == self.hwnd, "invalid hwnd: %s (expected %s)" % ( hWnd, self.hwnd) callbacks = self.event_callbacks.get(msg) event_name = KNOWN_WM_EVENTS.get(msg, msg) log("callbacks for event %s: %s", event_name, callbacks) if callbacks: for c in callbacks: try: c(wParam, lParam) except: log.error("error in callback %s", c, exc_info=True) elif msg in IGNORE_EVENTS: log("%s: %s / %s", IGNORE_EVENTS.get(msg), wParam, lParam) elif msg in LOG_EVENTS: log.info("%s: %s / %s", LOG_EVENTS.get(msg), wParam, lParam) #elif msg==win32con.WM_ACTIVATEAPP: # log("WM_ACTIVATEAPP focus changed: %s / %s", wParam, lParam) else: log.warn("unexpected message: %s / %s / %s", event_name, wParam, lParam) # Pass all messages to the original WndProc try: return win32gui.CallWindowProc(self.old_win32_proc, hWnd, msg, wParam, lParam) except Exception, e: log.error("error delegating call for %s: %s", event_name, e)
def WndProc(self, hWnd, msg, wParam, lParam): if msg == win32con.WM_USER: if wParam == 0 and lParam == 1: self.Show() self.Raise() elif msg == win32con.WM_DESTROY: win32api.SetWindowLong(self.GetHandle(), win32con.GWL_WNDPROC, self.oldWndProc) return win32gui.CallWindowProc(self.oldWndProc, hWnd, msg, wParam, lParam)
def localWndProc(self, hWnd, msg, wParam, lParam): if msg in self.msgDict: if self.msgDict[msg](wParam, lParam) == False: return if msg == win32con.WM_DESTROY: self.unhookWndProc() return win32gui.CallWindowProc(self.oldWndProc, hWnd, msg, wParam, lParam)
def _wndproc(self, hwnd, msg, wparam, lparam): """ A WINDPROC to process window messages. """ if self._message_map.has_key(msg): callback = self._message_map[msg] if isinstance(callback, list): for cb in callback: apply(cb, (hwnd, msg, wparam, lparam)) else: apply(callback, (hwnd, msg, wparam, lparam)) return win32gui.CallWindowProc(self._oldwndproc, hwnd, msg, wparam, lparam)
def MyWndProc(self, hWnd, msg, wParam, lParam): # Display what we've got. print (self.msgdict.get(msg), msg, wParam, lParam) # Restore the old WndProc. Notice the use of wxin32api # instead of win32gui here. This is to avoid an error due to # not passing a callable object. if msg == win32con.WM_DESTROY: win32api.SetWindowLong(self.GetHandle(),win32con.GWL_WNDPROC,self.oldWndProc) # Pass all messages (in this case, yours may be different) on # to the original WndProc return win32gui.CallWindowProc(self.oldWndProc,hWnd, msg, wParam, lParam)
def __WndProc(self, hWnd, msg, wParam, lParam): if msg == win32con.WM_DESTROY: win32api.SetWindowLong(self.GetHandle(), win32con.GWL_WNDPROC, self.__oldProc) if msg == win32con.WM_POWERBROADCAST: if wParam == win32con.PBT_APMSUSPEND: wx.CallAfter(self.OnPowerState, self.POWEROFF) elif wParam == win32con.PBT_APMRESUMESUSPEND: wx.CallAfter(self.OnPowerState, self.POWERON) return win32gui.CallWindowProc(self.__oldProc, hWnd, msg, wParam, lParam)
def __WndProc(self, hWnd, msg, wParam, lParam): if msg == win32con.WM_POWERBROADCAST: if wParam == win32con.PBT_APMSUSPEND: log("Power off") self.poweroff.emit() elif wParam == win32con.PBT_APMRESUMESUSPEND: log("Power ON") self.poweron.emit() else: win32api.SetWindowLong(self.widget.winId(), win32con.GWL_WNDPROC, self.__oldProc) return win32gui.CallWindowProc(self.__oldProc, hWnd, msg, wParam, lParam)
def window_procedure(window_handle, mesg_type, w_param, l_param): if mesg_type == win32con.WM_GETMINMAXINFO: info = MINMAXINFO.from_address(l_param) info.ptMinTrackSize.x = WINDOW_SIZE_MIN_WIDTH info.ptMinTrackSize.y = WINDOW_SIZE_MIN_HEIGHT elif mesg_type == win32con.WM_DESTROY: # Fix hanging on close win32api.SetWindowLong(self.window_handle, win32con.GWL_WNDPROC, old_window_procedure) return win32gui.CallWindowProc(old_window_procedure, window_handle, mesg_type, w_param, l_param)
def _InputHandler(hwnd, msg, wparam, lparam): global _lastCursorAtDesktop, _cursorAtDesktop, _lastMousePos # 避免 Windows 10 自动发送鼠标离开的消息,从而无法触发浏览器的 hover if msg == win32con.WM_MOUSELEAVE: if _cursorAtDesktop: return False elif msg == 0xFF: dataSize = ctypes.c_ulong(0) ctypes.windll.user32.GetRawInputData(lparam, 0x10000003, None, ctypes.byref(dataSize), ctypes.sizeof(RAWINPUTHEADER)) dataBuf = ctypes.create_string_buffer(dataSize.value) ctypes.windll.user32.GetRawInputData(lparam, 0x10000003, dataBuf, ctypes.byref(dataSize), ctypes.sizeof(RAWINPUTHEADER)) inputData = ctypes.cast(dataBuf, ctypes.POINTER(RAWINPUT)) if inputData.contents.header.dwType == 0: mouse = inputData.contents.data.mouse lastMousePos = win32gui.GetCursorPos() # 获得鼠标当前所在的屏幕坐标 # 鼠标移动的相对坐标(暂时没啥用) '''if mouse.usFlags & 1: _lastMousePos[0] = int((mouse.lLastX / 65535.0) * screenSize[0]) _lastMousePos[1] = int((mouse.lLastY / 65535.0) * screenSize[1]) else: _lastMousePos[0] += mouse.lLastX _lastMousePos[1] += mouse.lLastY''' # 获得鼠标当前指向的窗口句柄 cursorAt = win32gui.WindowFromPoint( (lastMousePos[0], lastMousePos[1])) # 检测到鼠标指向的是桌面(桌面显示图标时是 _syslistview,隐藏图标时是 _defview) _cursorAtDesktop = (cursorAt == _defview or cursorAt == _syslistview) if _cursorAtDesktop: win32gui.PostMessage(_legacy, win32con.WM_MOUSEMOVE, 0, (lastMousePos[1] << 16) | lastMousePos[0]) elif _lastCursorAtDesktop and not _cursorAtDesktop: win32gui.PostMessage(hwnd, win32con.WM_MOUSELEAVE, 0, 0) _lastCursorAtDesktop = _cursorAtDesktop return win32gui.CallWindowProc(_wndproc0, hwnd, msg, wparam, lparam)
def MyWndProc(self, hWnd, msg, wParam, lParam): assert hWnd == self.getHWND(), "invalid hwnd: %s (expected %s)" % ( hWnd, self.getHWND()) if msg in IGNORE_EVENTS: debug("%s: %s / %s", IGNORE_EVENTS.get(msg), wParam, lParam) elif msg == WM_TRAY_EVENT: self.tray_event(wParam, lParam) elif msg == win32con.WM_ACTIVATEAPP: debug("WM_ACTIVATEAPP focus changed: %s / %s", wParam, lParam) else: log.warn("unexpected message: %s / %s / %s", KNOWN_WM_EVENTS.get(msg, msg), wParam, lParam) # Pass all messages to the original WndProc try: return win32gui.CallWindowProc(self.old_win32_proc, hWnd, msg, wParam, lParam) except Exception, e: log.error("error delegating call: %s", e)
def editwndproc(hwnd, msg, wParam, lParam): # print("EW: %08x %08x %08x"%(msg, wParam, lParam)) if msg == win32con.WM_CHAR: if wParam == win32con.VK_RETURN: if self.exec_command(win32gui.GetWindowText( self.hwnd_edit)): return 0 if wParam == win32con.VK_ESCAPE: win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE) return 0 if msg == win32con.WM_KEYDOWN: if wParam == win32con.VK_UP: self.next_candidate(-1) return 0 if wParam == win32con.VK_DOWN: self.next_candidate(1) return 0 return win32gui.CallWindowProc(self.old_editwndproc, hwnd, msg, wParam, lParam)
def WindowProc(Hwnd,uMsg,wParam,lParam): if uMsg==msgShellHook: if wParam==1: #HSHELL_WINDOWCREATED pass print("钩取到窗口创建消息") elif wParam==2: #HSHELL_WINDOWDESTROYED pass print("钩取到窗口销毁消息") elif wParam==3: #HSHELL_ACTIVATESHELLWINDOW pass elif wParam==6: #HSHELL_REDRAW GetForegroundInfo() print("钩取到窗口重绘消息") elif wParam==32772: #ACTIVATE GetForegroundInfo() print("钩取到窗口激活消息") else: pass return win32gui.CallWindowProc(lpPrevWndProc,Hwnd,uMsg,wParam,lParam)
def MyWndProc(self, hWnd, msg, wParam, lParam): if msg == win32con.WM_CHANGECBCHAIN: self.OnChangeCBChain(msg, wParam, lParam) elif msg == win32con.WM_DRAWCLIPBOARD: self.OnDrawClipboard(msg, wParam, lParam) if msg == win32con.WM_DESTROY: if self.nextWnd: win32clipboard.ChangeClipboardChain(self.hwnd, self.nextWnd) else: win32clipboard.ChangeClipboardChain(self.hwnd, 0) win32api.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, self.oldWndProc) # 分析并保存结果 self.save_proxies() self.clipboard.Close() return win32gui.CallWindowProc(self.oldWndProc, hWnd, msg, wParam, lParam)
def MyWndProc(self, hWnd, msg, wParam, lParam): callbacks = self.event_callbacks.get(msg) event_name = KNOWN_WM_EVENTS.get(msg, hex(msg)) log("callbacks for event %s: %s", event_name, callbacks) if hWnd == self.hwnd: if callbacks: for c in callbacks: try: c(wParam, lParam) except: log.error("error in callback %s", c, exc_info=True) elif msg in IGNORE_EVENTS: log("%s: %s / %s", IGNORE_EVENTS.get(msg), wParam, lParam) elif msg in LOG_EVENTS: log.info("%s: %s / %s", LOG_EVENTS.get(msg), wParam, lParam) #elif msg==win32con.WM_ACTIVATEAPP: # log("WM_ACTIVATEAPP focus changed: %s / %s", wParam, lParam) else: l = log.warn if (msg >= 0 and msg <= win32con.WM_USER) or msg > 0xFFFF: ut = "reserved system" elif msg >= win32con.WM_USER and msg <= 0x7FFF: ut = "WM_USER" elif msg >= 0x8000 and msg <= 0xBFFF: ut = "WM_APP" elif msg >= 0xC000 and msg <= 0xFFFF: ut = "string" l = log.info else: ut = "/ unexpected" l("unknown %s message: %s / %s / %s", ut, event_name, wParam, lParam) else: log.warn("invalid hwnd: %s (expected %s)", hWnd, self.hwnd) # Pass all messages to the original WndProc try: return win32gui.CallWindowProc(self.old_win32_proc, hWnd, msg, wParam, lParam) except Exception as e: log.error("error delegating call for %s: %s", event_name, e)
def MyWndProc(self, hWnd, msg, wParam, lParam): if msg == win32con.WM_CHANGECBCHAIN: self.OnChangeCBChain(msg, wParam, lParam) elif msg == win32con.WM_DRAWCLIPBOARD: self.OnDrawClipboard(msg, wParam, lParam) # Restore the old WndProc. Notice the use of win32api # instead of win32gui here. This is to avoid an error due to # not passing a callable object. if msg == win32con.WM_DESTROY: if self.nextWnd: win32clipboard.ChangeClipboardChain(self.hwnd, self.nextWnd) else: win32clipboard.ChangeClipboardChain(self.hwnd, 0) win32api.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, self.oldWndProc) # Pass all messages (in this case, yours may be different) on # to the original WndProc return win32gui.CallWindowProc(self.oldWndProc, hWnd, msg, wParam, lParam)