我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用win32gui.PumpWaitingMessages()。
def TestSetWorldTransform(): wc = win32gui.WNDCLASS() wc.lpszClassName = 'test_win32gui_1' wc.style = win32con.CS_GLOBALCLASS|win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW+1 wc.lpfnWndProc=wndproc_1 class_atom=win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindow(wc.lpszClassName, 'Spin the Lobster!', win32con.WS_CAPTION|win32con.WS_VISIBLE, 100,100,900,900, 0, 0, 0, None) for x in xrange(500): win32gui.InvalidateRect(hwnd,None,True) win32gui.PumpWaitingMessages() time.sleep(0.01) win32gui.DestroyWindow(hwnd) win32gui.UnregisterClass(wc.lpszClassName, None)
def TestGradientFill(): wc = win32gui.WNDCLASS() wc.lpszClassName = 'test_win32gui_2' wc.style = win32con.CS_GLOBALCLASS|win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW+1 wc.lpfnWndProc=wndproc_2 class_atom=win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindowEx(0, class_atom,'Kaleidoscope', win32con.WS_CAPTION|win32con.WS_VISIBLE|win32con.WS_THICKFRAME|win32con.WS_SYSMENU, 100,100,900,900, 0, 0, 0, None) s=win32gui.GetWindowLong(hwnd,win32con.GWL_EXSTYLE) win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, s|win32con.WS_EX_LAYERED) win32gui.SetLayeredWindowAttributes(hwnd, 0, 175, win32con.LWA_ALPHA) for x in xrange(30): win32gui.InvalidateRect(hwnd,None,True) win32gui.PumpWaitingMessages() time.sleep(0.3) win32gui.DestroyWindow(hwnd) win32gui.UnregisterClass(class_atom,None)
def TestSetWorldTransform(): wc = win32gui.WNDCLASS() wc.lpszClassName = 'test_win32gui_1' wc.style = win32con.CS_GLOBALCLASS|win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW+1 wc.lpfnWndProc=wndproc_1 class_atom=win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindow(wc.lpszClassName, 'Spin the Lobster!', win32con.WS_CAPTION|win32con.WS_VISIBLE, 100,100,900,900, 0, 0, 0, None) for x in range(500): win32gui.InvalidateRect(hwnd,None,True) win32gui.PumpWaitingMessages() time.sleep(0.01) win32gui.DestroyWindow(hwnd) win32gui.UnregisterClass(wc.lpszClassName, None)
def TestGradientFill(): wc = win32gui.WNDCLASS() wc.lpszClassName = 'test_win32gui_2' wc.style = win32con.CS_GLOBALCLASS|win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW+1 wc.lpfnWndProc=wndproc_2 class_atom=win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindowEx(0, class_atom,'Kaleidoscope', win32con.WS_CAPTION|win32con.WS_VISIBLE|win32con.WS_THICKFRAME|win32con.WS_SYSMENU, 100,100,900,900, 0, 0, 0, None) s=win32gui.GetWindowLong(hwnd,win32con.GWL_EXSTYLE) win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, s|win32con.WS_EX_LAYERED) win32gui.SetLayeredWindowAttributes(hwnd, 0, 175, win32con.LWA_ALPHA) for x in range(30): win32gui.InvalidateRect(hwnd,None,True) win32gui.PumpWaitingMessages() time.sleep(0.3) win32gui.DestroyWindow(hwnd) win32gui.UnregisterClass(class_atom,None)
def start(self): if self.instance_running(): try: self.stop() except SystemExit: return win32gui.PostQuitMessage(0) # Load today's count data back from data file super(KeyCounter, self).start() self.hook_keyboard() self.create_window() self.update_tray_icon() while 1: try: win32event.MsgWaitForMultipleObjects( [], 0, self.MSPF, win32event.QS_ALLEVENTS ) win32gui.PumpWaitingMessages() except SystemExit: win32gui.PostQuitMessage(0)
def doWaitForMultipleEvents(self, timeout, reads=reads, writes=writes): log.msg(channel='system', event='iteration', reactor=self) if timeout is None: #timeout = INFINITE timeout = 100 else: timeout = int(timeout * 1000) if not (events or writes): # sleep so we don't suck up CPU time time.sleep(timeout / 1000.0) return canDoMoreWrites = 0 for fd in writes.keys(): if log.callWithLogger(fd, self._runWrite, fd): canDoMoreWrites = 1 if canDoMoreWrites: timeout = 0 handles = events.keys() or [self.dummyEvent] val = MsgWaitForMultipleObjects(handles, 0, timeout, QS_ALLINPUT | QS_ALLEVENTS) if val == WAIT_TIMEOUT: return elif val == WAIT_OBJECT_0 + len(handles): exit = win32gui.PumpWaitingMessages() if exit: self.callLater(0, self.stop) return elif val >= WAIT_OBJECT_0 and val < WAIT_OBJECT_0 + len(handles): fd, action = events[handles[val - WAIT_OBJECT_0]] log.callWithLogger(fd, self._runAction, action, fd)
def demo (delay=1000, stop=10): g = glork(delay, stop) # Timers are message based - so we need # To run a message loop while waiting for our timers # to expire. start_time = time.time() while 1: # We can't simply give a timeout of 30 seconds, as # we may continouusly be recieving other input messages, # and therefore never expire. rc = win32event.MsgWaitForMultipleObjects( (g.event,), # list of objects 0, # wait all 500, # timeout win32event.QS_ALLEVENTS, # type of input ) if rc == win32event.WAIT_OBJECT_0: # Event signalled. break elif rc == win32event.WAIT_OBJECT_0+1: # Message waiting. if win32gui.PumpWaitingMessages(): raise RuntimeError("We got an unexpected WM_QUIT message!") else: # This wait timed-out. if time.time()-start_time > 30: raise RuntimeError("We timed out waiting for the timers to expire!")
def TestDeviceNotifications(dir_names): wc = win32gui.WNDCLASS() wc.lpszClassName = 'test_devicenotify' wc.style = win32con.CS_GLOBALCLASS|win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW+1 wc.lpfnWndProc={win32con.WM_DEVICECHANGE:OnDeviceChange} class_atom=win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindow(wc.lpszClassName, 'Testing some devices', # no need for it to be visible. win32con.WS_CAPTION, 100,100,900,900, 0, 0, 0, None) hdevs = [] # Watch for all USB device notifications filter = win32gui_struct.PackDEV_BROADCAST_DEVICEINTERFACE( GUID_DEVINTERFACE_USB_DEVICE) hdev = win32gui.RegisterDeviceNotification(hwnd, filter, win32con.DEVICE_NOTIFY_WINDOW_HANDLE) hdevs.append(hdev) # and create handles for all specified directories for d in dir_names: hdir = win32file.CreateFile(d, winnt.FILE_LIST_DIRECTORY, winnt.FILE_SHARE_READ | winnt.FILE_SHARE_WRITE | winnt.FILE_SHARE_DELETE, None, # security attributes win32con.OPEN_EXISTING, win32con.FILE_FLAG_BACKUP_SEMANTICS | # required privileges: SE_BACKUP_NAME and SE_RESTORE_NAME. win32con.FILE_FLAG_OVERLAPPED, None) filter = win32gui_struct.PackDEV_BROADCAST_HANDLE(hdir) hdev = win32gui.RegisterDeviceNotification(hwnd, filter, win32con.DEVICE_NOTIFY_WINDOW_HANDLE) hdevs.append(hdev) # now start a message pump and wait for messages to be delivered. print("Watching", len(hdevs), "handles - press Ctrl+C to terminate, or") print("add and remove some USB devices...") if not dir_names: print("(Note you can also pass paths to watch on the command-line - eg,") print("pass the root of an inserted USB stick to see events specific to") print("that volume)") while 1: win32gui.PumpWaitingMessages() time.sleep(0.01) win32gui.DestroyWindow(hwnd) win32gui.UnregisterClass(wc.lpszClassName, None)
def TestDeviceNotifications(dir_names): wc = win32gui.WNDCLASS() wc.lpszClassName = 'test_devicenotify' wc.style = win32con.CS_GLOBALCLASS|win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW+1 wc.lpfnWndProc={win32con.WM_DEVICECHANGE:OnDeviceChange} class_atom=win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindow(wc.lpszClassName, 'Testing some devices', # no need for it to be visible. win32con.WS_CAPTION, 100,100,900,900, 0, 0, 0, None) hdevs = [] # Watch for all USB device notifications filter = win32gui_struct.PackDEV_BROADCAST_DEVICEINTERFACE( GUID_DEVINTERFACE_USB_DEVICE) hdev = win32gui.RegisterDeviceNotification(hwnd, filter, win32con.DEVICE_NOTIFY_WINDOW_HANDLE) hdevs.append(hdev) # and create handles for all specified directories for d in dir_names: hdir = win32file.CreateFile(d, winnt.FILE_LIST_DIRECTORY, winnt.FILE_SHARE_READ | winnt.FILE_SHARE_WRITE | winnt.FILE_SHARE_DELETE, None, # security attributes win32con.OPEN_EXISTING, win32con.FILE_FLAG_BACKUP_SEMANTICS | # required privileges: SE_BACKUP_NAME and SE_RESTORE_NAME. win32con.FILE_FLAG_OVERLAPPED, None) filter = win32gui_struct.PackDEV_BROADCAST_HANDLE(hdir) hdev = win32gui.RegisterDeviceNotification(hwnd, filter, win32con.DEVICE_NOTIFY_WINDOW_HANDLE) hdevs.append(hdev) # now start a message pump and wait for messages to be delivered. print "Watching", len(hdevs), "handles - press Ctrl+C to terminate, or" print "add and remove some USB devices..." if not dir_names: print "(Note you can also pass paths to watch on the command-line - eg," print "pass the root of an inserted USB stick to see events specific to" print "that volume)" while 1: win32gui.PumpWaitingMessages() time.sleep(0.01) win32gui.DestroyWindow(hwnd) win32gui.UnregisterClass(wc.lpszClassName, None)
def icon_wndproc(hwnd, msg, wp, lp): """ Window proc for the tray icons """ if lp==win32con.WM_LBUTTONDOWN: ## popup menu won't disappear if you don't do this win32gui.SetForegroundWindow(hwnd) curr_desktop=win32service.OpenInputDesktop(0,True,win32con.MAXIMUM_ALLOWED) curr_desktop_name=win32service.GetUserObjectInformation(curr_desktop,win32con.UOI_NAME) winsta=win32service.GetProcessWindowStation() desktops=winsta.EnumDesktops() m=win32gui.CreatePopupMenu() desktop_cnt=len(desktops) ## *don't* create an item 0 for d in range(1, desktop_cnt+1): mf_flags=win32con.MF_STRING ## if you switch to winlogon yourself, there's nothing there and you're stuck if desktops[d-1].lower() in ('winlogon','disconnect'): mf_flags=mf_flags|win32con.MF_GRAYED|win32con.MF_DISABLED if desktops[d-1]==curr_desktop_name: mf_flags=mf_flags|win32con.MF_CHECKED win32gui.AppendMenu(m, mf_flags, d, desktops[d-1]) win32gui.AppendMenu(m, win32con.MF_STRING, desktop_cnt+1, 'Create new ...') win32gui.AppendMenu(m, win32con.MF_STRING, desktop_cnt+2, 'Exit') x,y=win32gui.GetCursorPos() d=win32gui.TrackPopupMenu(m,win32con.TPM_LEFTBUTTON|win32con.TPM_RETURNCMD|win32con.TPM_NONOTIFY, x,y, 0, hwnd, None) win32gui.PumpWaitingMessages() win32gui.DestroyMenu(m) if d==desktop_cnt+1: ## Create new get_new_desktop_name(hwnd) elif d==desktop_cnt+2: ## Exit win32gui.PostQuitMessage(0) win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, window_info[hwnd]) del window_info[hwnd] origin_desktop.SwitchDesktop() elif d>0: hdesk=win32service.OpenDesktop(desktops[d-1],0,0,win32con.MAXIMUM_ALLOWED) hdesk.SwitchDesktop() return 0 else: return win32gui.DefWindowProc(hwnd, msg, wp, lp)