我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用win32api.PostMessage()。
def Run(self): while 1: handles = [self.stopEvent, self.adminEvent] if self.watchEvent is not None: handles.append(self.watchEvent) rc = win32event.WaitForMultipleObjects(handles, 0, win32event.INFINITE) if rc == win32event.WAIT_OBJECT_0: break elif rc == win32event.WAIT_OBJECT_0+1: self.RefreshEvent() else: win32api.PostMessage(self.hwnd, MSG_CHECK_EXTERNAL_FILE, 0, 0) try: # If the directory has been removed underneath us, we get this error. win32api.FindNextChangeNotification(self.watchEvent) except win32api.error, exc: print "Can not watch file", self.doc.GetPathName(), "for changes -", exc.strerror break # close a circular reference self.doc = None if self.watchEvent: win32api.FindCloseChangeNotification(self.watchEvent)
def Run(self): while 1: handles = [self.stopEvent, self.adminEvent] if self.watchEvent is not None: handles.append(self.watchEvent) rc = win32event.WaitForMultipleObjects(handles, 0, win32event.INFINITE) if rc == win32event.WAIT_OBJECT_0: break elif rc == win32event.WAIT_OBJECT_0+1: self.RefreshEvent() else: win32api.PostMessage(self.hwnd, MSG_CHECK_EXTERNAL_FILE, 0, 0) try: # If the directory has been removed underneath us, we get this error. win32api.FindNextChangeNotification(self.watchEvent) except win32api.error as exc: print("Can not watch file", self.doc.GetPathName(), "for changes -", exc.strerror) break # close a circular reference self.doc = None if self.watchEvent: win32api.FindCloseChangeNotification(self.watchEvent)
def move(self,coords, button=None): if all(isinstance(elem, float) for elem in coords): coords = self.to_pixel(coords) if button == None: _button_state = 0 elif "right" in button.lower(): _button_state = win32con.MK_RBUTTON elif "left" in button.lower(): _button_state = win32con.MK_LBUTTON elif "middle" in button.lower(): _button_state = win32con.MK_MBUTTON else: raise SyntaxError('"Button" needs to contain "left", "right" or "middle"') l_param = win32api.MAKELONG(coords[0], coords[1]) win32api.PostMessage(self.win_handler.get_hwnd(), win32con.WM_MOUSEMOVE, _button_state, l_param)
def __init__(self, reactor): def stopThreads(): for t in self.threadToMsgWindow.keys(): # PostMessage blocks for dead threads if t.isAlive() and self.threadToMsgWindowCreated[t]: win32api.PostMessage( self.threadToMsgWindow[t], # thread id WM_CLOSE_THREAD, # message 0, # wParam 0 # lParam ) reactor.addSystemEventTrigger("before", "shutdown", stopThreads)
def notifyOnExit(self, processHandle, processTransport): processHandleKey = self.phandleToPhandleKey[processHandle] # If there are available threads, use one of them if len(self.availableThreads) > 0: wfmoThread = self.availableThreads[0] self.threadToNumProcessHandles[wfmoThread] += 1 self.phandleKeyToThreadHandle[processHandleKey] = wfmoThread # Update used/available thread lists if self.threadToNumProcessHandles[wfmoThread] == 63: self.usedThreads.append(wfmoThread) self.availableThreads.remove(wfmoThread) # Make sure the message window has been created so # we can send messages to the thread. if self.threadToMsgWindowCreated[wfmoThread] is False: val = WaitForSingleObject(self.threadToMsgWindowCreationEvent[wfmoThread], INFINITE) if val != WAIT_OBJECT_0: raise RuntimeError("WaitForSingleObject returned %d. It should only return %d" % (val, WAIT_OBJECT_0)) # Notify the thread that it should wait on the process handle. if win32api.PostMessage( self.threadToMsgWindow[wfmoThread], WM_NEW_PHANDLE, # message processHandleKey, # wParam 0 # lParam ) == 0: raise Exception("Failed to post thread message!") else: # Create a new thread and wait on the proc handle wfmoThread = threading.Thread( target=self.doWaitForProcessExit, args=(processHandleKey,), name="iocpreactor.process_waiter.ProcessWaiter.waitForProcessExit pid=%d" % self.realPid) # Create a window creation event that will be triggered from the thread self.threadToMsgWindowCreationEvent[wfmoThread] = CreateEvent(None, 0, 0, None) self.threadToMsgWindowCreated[wfmoThread] = False self.threadToNumProcessHandles[wfmoThread] = 1 self.availableThreads.append(wfmoThread) self.phandleKeyToThreadHandle[processHandleKey] = wfmoThread wfmoThread.start()
def processEnded(self, processHandle, processHandleKey): wfmoThread = self.phandleKeyToThreadHandle[processHandleKey] processTransport = self.phandleToTransport[processHandle] self.threadToNumEnded[wfmoThread] += 1 # Decrement proc handle count for thread self.threadToNumProcessHandles[wfmoThread] -= 1 # If we go from 63 to 62 phandles for the thread, mark it available. if self.threadToNumProcessHandles[wfmoThread] == 62: self.availableThreads.append(wfmoThread) self.usedThreads.remove(wfmoThread) # If we go to 0 phandles, end the thread elif self.threadToNumProcessHandles[wfmoThread] == 0: # Mark thread as unavailable self.availableThreads.remove(wfmoThread) # Notify the thread that it should exit. if not self.threadToMsgWindowCreated[wfmoThread]: val = WaitForSingleObject(self.threadToMsgWindowCreationEvent[wfmoThread], INFINITE) if val != WAIT_OBJECT_0: raise RuntimeError("WaitForSingleObject returned %d. It should only return %d" % (val, WAIT_OBJECT_0)) # Notify the thread that it should wait on the process handle. win32api.PostMessage( self.threadToMsgWindow[wfmoThread], # thread id WM_CLOSE_THREAD, # message 0, # wParam 0 # lParam ) # Cleanup thread resources del self.threadToNumProcessHandles[wfmoThread] del self.threadToMsgWindowCreated[wfmoThread] #del self.wfmoThread # Cleanup process handle resources del self.needWaiting[processHandleKey] del self.phandleToTransport[processHandle] # Call the transport's processEnded method processTransport.processEnded()
def NotifyAutoxdShow(self, code): return 0 #???? hwnd = LiveData().getFrameHwnd() code = int(code) #lparam????????, wparam???0??? try: win32api.PostMessage(hwnd,0x400+101,code,6-len(str(code))) except: pass
def OnTaskbarNotify( self, hwnd, msg, wparam, lparam, ): if lparam == win32con.WM_LBUTTONUP: pass elif lparam == win32con.WM_LBUTTONDBLCLK: pass elif lparam == win32con.WM_RBUTTONUP: menu = win32gui.CreatePopupMenu() win32gui.AppendMenu(menu, win32con.MF_STRING, 1023, 'Toggle Display') win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 0, '') if self.serverState == self.EnumServerState.STOPPED: win32gui.AppendMenu(menu, win32con.MF_STRING, 1024, 'Start Server') win32gui.AppendMenu(menu, win32con.MF_STRING | win32con.MF_GRAYED, 1025, 'Restart Server') win32gui.AppendMenu(menu, win32con.MF_STRING | win32con.MF_GRAYED, 1026, 'Stop Server') else: win32gui.AppendMenu(menu, win32con.MF_STRING | win32con.MF_GRAYED, 1024, 'Start Server') win32gui.AppendMenu(menu, win32con.MF_STRING, 1025, 'Restart Server') win32gui.AppendMenu(menu, win32con.MF_STRING, 1026, 'Stop Server') win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 0, '') win32gui.AppendMenu(menu, win32con.MF_STRING, 1027, 'Quit (pid:%i)' % os.getpid()) pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu( menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None, ) win32api.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0) return 1
def _get_handles(self): trade_main_hwnd = win32gui.FindWindow(0, self.Title) # ???? operate_frame_hwnd = win32gui.GetDlgItem(trade_main_hwnd, 59648) # ?????? operate_frame_afx_hwnd = win32gui.GetDlgItem(operate_frame_hwnd, 59648) # ?????? hexin_hwnd = win32gui.GetDlgItem(operate_frame_afx_hwnd, 129) scroll_hwnd = win32gui.GetDlgItem(hexin_hwnd, 200) # ???????? tree_view_hwnd = win32gui.GetDlgItem(scroll_hwnd, 129) # ???????? # ???????????? win32api.PostMessage(tree_view_hwnd, win32con.WM_KEYDOWN, win32con.VK_F1, 0) time.sleep(0.5) # ???? entrust_window_hwnd = win32gui.GetDlgItem(operate_frame_hwnd, 59649) # ?????? self.buy_stock_code_hwnd = win32gui.GetDlgItem(entrust_window_hwnd, 1032) # ??????? self.buy_price_hwnd = win32gui.GetDlgItem(entrust_window_hwnd, 1033) # ??????? self.buy_amount_hwnd = win32gui.GetDlgItem(entrust_window_hwnd, 1034) # ??????? self.buy_btn_hwnd = win32gui.GetDlgItem(entrust_window_hwnd, 1006) # ?????? self.refresh_entrust_hwnd = win32gui.GetDlgItem(entrust_window_hwnd, 32790) # ?????? entrust_frame_hwnd = win32gui.GetDlgItem(entrust_window_hwnd, 1047) # ?????? entrust_sub_frame_hwnd = win32gui.GetDlgItem(entrust_frame_hwnd, 200) # ?????? self.position_list_hwnd = win32gui.GetDlgItem(entrust_sub_frame_hwnd, 1047) # ???? win32api.PostMessage(tree_view_hwnd, win32con.WM_KEYDOWN, win32con.VK_F2, 0) time.sleep(0.5) # ???? sell_entrust_frame_hwnd = win32gui.GetDlgItem(operate_frame_hwnd, 59649) # ?????? self.sell_stock_code_hwnd = win32gui.GetDlgItem(sell_entrust_frame_hwnd, 1032) # ??????? self.sell_price_hwnd = win32gui.GetDlgItem(sell_entrust_frame_hwnd, 1033) # ??????? self.sell_amount_hwnd = win32gui.GetDlgItem(sell_entrust_frame_hwnd, 1034) # ??????? self.sell_btn_hwnd = win32gui.GetDlgItem(sell_entrust_frame_hwnd, 1006) # ?????? # ???? win32api.PostMessage(tree_view_hwnd, win32con.WM_KEYDOWN, win32con.VK_F3, 0) time.sleep(0.5) cancel_entrust_window_hwnd = win32gui.GetDlgItem(operate_frame_hwnd, 59649) # ?????? self.cancel_stock_code_hwnd = win32gui.GetDlgItem(cancel_entrust_window_hwnd, 3348) # ??????? self.cancel_query_hwnd = win32gui.GetDlgItem(cancel_entrust_window_hwnd, 3349) # ?????? self.cancel_buy_hwnd = win32gui.GetDlgItem(cancel_entrust_window_hwnd, 30002) # ?? self.cancel_sell_hwnd = win32gui.GetDlgItem(cancel_entrust_window_hwnd, 30003) # ?? chexin_hwnd = win32gui.GetDlgItem(cancel_entrust_window_hwnd, 1047) chexin_sub_hwnd = win32gui.GetDlgItem(chexin_hwnd, 200) self.entrust_list_hwnd = win32gui.GetDlgItem(chexin_sub_hwnd, 1047) # ????