Python win32gui.SendMessage() Examples
The following are 30
code examples of win32gui.SendMessage().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32gui
, or try the search function
.
Example #1
Source File: win32gui_dialog.py From ironpython2 with Apache License 2.0 | 9 votes |
def OnCommand(self, hwnd, msg, wparam, lparam): id = win32api.LOWORD(wparam) if id == IDC_BUTTON_SEARCH: self.ClearListItems() def fill_slowly(q, hwnd): import time for i in range(20): q.put(("whatever", str(i+1), "Search result " + str(i) )) win32gui.PostMessage(hwnd, WM_SEARCH_RESULT, 0, 0) time.sleep(.25) win32gui.PostMessage(hwnd, WM_SEARCH_FINISHED, 0, 0) import threading self.result_queue = Queue.Queue() thread = threading.Thread(target = fill_slowly, args=(self.result_queue, self.hwnd) ) thread.start() elif id == IDC_BUTTON_DISPLAY: print "Display button selected" sel = win32gui.SendMessage(self.hwndList, commctrl.LVM_GETNEXTITEM, -1, commctrl.LVNI_SELECTED) print "The selected item is", sel+1 # These function differ based on how the window is used, so may be overridden
Example #2
Source File: shell_view.py From ironpython2 with Apache License 2.0 | 8 votes |
def CreateViewWindow(self, prev, settings, browser, rect): print "FileSystemView.CreateViewWindow", prev, settings, browser, rect self.cur_foldersettings = settings self.browser = browser self._CreateMainWindow(prev, settings, browser, rect) self._CreateChildWindow(prev) # This isn't part of the sample, but the most convenient place to # test/demonstrate how you can get an IShellBrowser from a HWND # (but ONLY when you are in the same process as the IShellBrowser!) # Obviously it is not necessary here - we already have the browser! browser_ad = win32gui.SendMessage(self.hwnd_parent, win32con.WM_USER+7, 0, 0) browser_ob = pythoncom.ObjectFromAddress(browser_ad, shell.IID_IShellBrowser) assert browser==browser_ob # and make a call on the object to prove it doesn't die :) assert browser.QueryActiveShellView()==browser_ob.QueryActiveShellView()
Example #3
Source File: cutthecrap.py From fame_modules with GNU General Public License v3.0 | 7 votes |
def foreach_child(self): def callback(hwnd, window_hwnd): classname = win32gui.GetClassName(hwnd).lower() buffer_len = win32gui.SendMessage(hwnd, win32con.WM_GETTEXTLENGTH, 0, 0) + 1 text = array('b', b'\x00\x00' * buffer_len) text_len = win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, buffer_len, text) text = win32gui.PyGetString(text.buffer_info()[0], buffer_len - 1).lower() for match in self._windows[window_hwnd]['matches']: if match["text"] in text: self._windows[window_hwnd]['to_click'].append(match["button"]) if "button" in classname: self._windows[window_hwnd]['buttons'].append({ 'text': text, 'handle': hwnd, }) return True return callback
Example #4
Source File: winguiauto.py From PyAutoTrading with GNU General Public License v2.0 | 6 votes |
def doubleClickStatic(hwnd): '''Simulates a double mouse click on a static Parameters ---------- hwnd Window handle of the required static. Usage example: TODO ''' _sendNotifyMessage(hwnd, win32con.STN_DBLCLK) # def getEditText(hwnd): # bufLen = win32gui.SendMessage(hwnd, win32con.WM_GETTEXTLENGTH, 0, 0) + 1 # print(bufLen) # buffer = win32gui.PyMakeBuffer(bufLen) # win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, bufLen, buffer) # # text = buffer[:bufLen] # return text
Example #5
Source File: shell_view.py From Email_My_PC with MIT License | 6 votes |
def CreateViewWindow(self, prev, settings, browser, rect): print "FileSystemView.CreateViewWindow", prev, settings, browser, rect self.cur_foldersettings = settings self.browser = browser self._CreateMainWindow(prev, settings, browser, rect) self._CreateChildWindow(prev) # This isn't part of the sample, but the most convenient place to # test/demonstrate how you can get an IShellBrowser from a HWND # (but ONLY when you are in the same process as the IShellBrowser!) # Obviously it is not necessary here - we already have the browser! browser_ad = win32gui.SendMessage(self.hwnd_parent, win32con.WM_USER+7, 0, 0) browser_ob = pythoncom.ObjectFromAddress(browser_ad, shell.IID_IShellBrowser) assert browser==browser_ob # and make a call on the object to prove it doesn't die :) assert browser.QueryActiveShellView()==browser_ob.QueryActiveShellView()
Example #6
Source File: winguiauto.py From pyautotrade_tdx with GNU General Public License v2.0 | 6 votes |
def doubleClickStatic(hwnd): '''Simulates a double mouse click on a static Parameters ---------- hwnd Window handle of the required static. Usage example: TODO ''' _sendNotifyMessage(hwnd, win32con.STN_DBLCLK) # def getEditText(hwnd): # bufLen = win32gui.SendMessage(hwnd, win32con.WM_GETTEXTLENGTH, 0, 0) + 1 # print(bufLen) # buffer = win32gui.PyMakeBuffer(bufLen) # win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, bufLen, buffer) # # text = buffer[:bufLen] # return text
Example #7
Source File: winguiauto.py From pyAutoTrading with GNU General Public License v2.0 | 6 votes |
def doubleClickStatic(hwnd): """Simulates a double mouse click on a static Parameters ---------- hwnd Window handle of the required static. Usage example: TODO """ _sendNotifyMessage(hwnd, win32con.STN_DBLCLK) # def getEditText(hwnd): # bufLen = win32gui.SendMessage(hwnd, win32con.WM_GETTEXTLENGTH, 0, 0) + 1 # print(bufLen) # buffer = win32gui.PyMakeBuffer(bufLen) # win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, bufLen, buffer) # # text = buffer[:bufLen] # return text
Example #8
Source File: win32gui_dialog.py From ironpython2 with Apache License 2.0 | 6 votes |
def _DoSize(self, cx, cy, repaint = 1): # right-justify the textbox. ctrl = win32gui.GetDlgItem(self.hwnd, IDC_SEARCHTEXT) l, t, r, b = win32gui.GetWindowRect(ctrl) l, t = win32gui.ScreenToClient(self.hwnd, (l,t) ) r, b = win32gui.ScreenToClient(self.hwnd, (r,b) ) win32gui.MoveWindow(ctrl, l, t, cx-l-5, b-t, repaint) # The button. ctrl = win32gui.GetDlgItem(self.hwnd, IDC_BUTTON_DISPLAY) l, t, r, b = win32gui.GetWindowRect(ctrl) l, t = win32gui.ScreenToClient(self.hwnd, (l,t) ) r, b = win32gui.ScreenToClient(self.hwnd, (r,b) ) list_y = b + 10 w = r - l win32gui.MoveWindow(ctrl, cx - 5 - w, t, w, b-t, repaint) # The list control win32gui.MoveWindow(self.hwndList, 0, list_y, cx, cy-list_y, repaint) # The last column of the list control. new_width = cx - win32gui.SendMessage(self.hwndList, commctrl.LVM_GETCOLUMNWIDTH, 0) win32gui.SendMessage(self.hwndList, commctrl.LVM_SETCOLUMNWIDTH, 1, new_width)
Example #9
Source File: cutthecrap.py From fame_modules with GNU General Public License v3.0 | 6 votes |
def foreach_window(self): def callback(hwnd, lparam): title = win32gui.GetWindowText(hwnd).lower() for window in self.to_close: if window in title: win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) print "Closed window ({})".format(title) for window in self.clicks: if window in title: self._windows[hwnd] = { "matches": self.clicks[window], "to_click": [], "buttons": [] } try: win32gui.EnumChildWindows(hwnd, self.foreach_child(), hwnd) except: print "EnumChildWindows failed, moving on." for button_toclick in self._windows[hwnd]['to_click']: for button in self._windows[hwnd]['buttons']: if button_toclick in button['text']: win32gui.SetForegroundWindow(button['handle']) win32gui.SendMessage(button['handle'], win32con.BM_CLICK, 0, 0) print "Clicked on button ({} / {})".format(title, button['text']) del self._windows[hwnd] return True return callback
Example #10
Source File: winguiauto.py From pyautotrade_tdx with GNU General Public License v2.0 | 6 votes |
def doubleClickStatic(hwnd): '''Simulates a double mouse click on a static Parameters ---------- hwnd Window handle of the required static. Usage example: TODO ''' _sendNotifyMessage(hwnd, win32con.STN_DBLCLK) # def getEditText(hwnd): # bufLen = win32gui.SendMessage(hwnd, win32con.WM_GETTEXTLENGTH, 0, 0) + 1 # print(bufLen) # buffer = win32gui.PyMakeBuffer(bufLen) # win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, bufLen, buffer) # # text = buffer[:bufLen] # return text
Example #11
Source File: game_ctl.py From onmyoji_bot with GNU General Public License v3.0 | 6 votes |
def quit_game(self): """ 退出游戏 """ self.takescreenshot() # 保存一下现场 self.clean_mem() # 清理内存 if not self.run: return False if self.quit_game_enable: if self.client == 0: win32gui.SendMessage( self.hwnd, win32con.WM_DESTROY, 0, 0) # 退出游戏 else: os.system( 'adb shell am force-stop com.netease.onmyoji.netease_simulator') logging.info('退出,最后显示已保存至/img/screenshots文件夹') sys.exit(0)
Example #12
Source File: game_ctl.py From onmyoji_bot with GNU General Public License v3.0 | 6 votes |
def mouse_drag_bg(self, pos1, pos2): """ 后台鼠标拖拽 :param pos1: (x,y) 起点坐标 :param pos2: (x,y) 终点坐标 """ if self.client == 0: move_x = np.linspace(pos1[0], pos2[0], num=20, endpoint=True)[0:] move_y = np.linspace(pos1[1], pos2[1], num=20, endpoint=True)[0:] win32gui.SendMessage(self.hwnd, win32con.WM_LBUTTONDOWN, 0, win32api.MAKELONG(pos1[0], pos1[1])) for i in range(20): x = int(round(move_x[i])) y = int(round(move_y[i])) win32gui.SendMessage( self.hwnd, win32con.WM_MOUSEMOVE, 0, win32api.MAKELONG(x, y)) time.sleep(0.01) win32gui.SendMessage(self.hwnd, win32con.WM_LBUTTONUP, 0, win32api.MAKELONG(pos2[0], pos2[1])) else: command = str(pos1[0])+' ' + str(pos1[1]) + \ ' '+str(pos2[0])+' '+str(pos2[1]) os.system('adb shell input swipe '+command)
Example #13
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def DefaultAction(self): sel = self.menuGridCtrl.GetSelection() item = self.items[sel] id = item[3] if id != -1: self.destroyMenu() SendMessage(self.hWnd, WM_COMMAND, id, 0) else: self.oldMenu.append((self.menu,sel)) self.menu = GetSubMenu(self.menu, item[1]) self.UpdateMenu()
Example #14
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __call__(self, val=""): if self.plugin.runFlg and self.plugin.mpcHwnd: try: val = eg.ParseString(val) val = int(val) except: raise self.Exception(self.text.error % val) return return SendMessage(self.plugin.mpcHwnd, WM_COMMAND, val, 0) else: raise self.Exceptions.ProgramNotRunning
Example #15
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __call__(self, action = -1): if action > -1: if self.plugin.runFlg and self.plugin.mpcHwnd: return SendMessage(self.plugin.mpcHwnd, WM_COMMAND, action + 912, 0) else: raise self.Exceptions.ProgramNotRunning
Example #16
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def getComboboxItems(self, hwnd): if self.only_sel: items = (win32guiSendMessage(hwnd, CB_GETCURSEL, 0, 0), ) else: items = None return self.getMultipleValues(hwnd, CB_GETCOUNT, CB_GETLBTEXT, items)
Example #17
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def GetItemList(menu, hWnd): SendMessage(hWnd, WM_INITMENUPOPUP, menu, 0) #REFRESH MENU STATE !!! itemList = [] itemName = c_buffer("\000" * 128) count = GetMenuItemCount(menu) for i in range(count): windll.user32.GetMenuStringA(c_int(menu), c_int(i), itemName, c_int(len(itemName)), MF_BYPOSITION) menuState = windll.user32.GetMenuState(c_int(menu), c_int(i), MF_BYPOSITION) id = windll.user32.GetMenuItemID(c_int(menu), c_int(i)) if menuState & (MF_GRAYED|MF_DISABLED): continue item = itemName.value.replace("&","").split("\t")[0] if item == "" and id == 0: continue checked = bool(menuState & MF_CHECKED) if isabs(item): if not isfile(item): continue else: item = split(item)[1] itemList.append((item, i, checked, id)) return itemList #===============================================================================
Example #18
Source File: win32_helper.py From pySPM with Apache License 2.0 | 5 votes |
def _sendNotifyMessage(hwnd, nofifyMessage): '''Send a notify message to a control.''' win32gui.SendMessage(win32gui.GetParent(hwnd), win32con.WM_COMMAND, _buildWinLong(nofifyMessage, win32api.GetWindowLong(hwnd, win32con.GWL_ID)), hwnd)
Example #19
Source File: win32_helper.py From pySPM with Apache License 2.0 | 5 votes |
def _getMultipleWindowValues(hwnd, getCountMessage, getValueMessage): result = [] VALUE_LENGTH = 256 valuecount = win32gui.SendMessage(hwnd, getCountMessage, 0, 0) for itemIndex in range(valuecount): valuebuffer = ctypes.create_unicode_buffer(VALUE_LENGTH) valueLength = win32gui.SendMessage(hwnd, getValueMessage, itemIndex, valuebuffer) result.append(valuebuffer[:valueLength]) return result
Example #20
Source File: win32_helper.py From pySPM with Apache License 2.0 | 5 votes |
def getText(hwnd): buffer_len = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0) + 1 buffer = array.array('b', b'\x00\x00' * buffer_len) text_len = SendMessage(hwnd, WM_GETTEXT, buffer_len, buffer) text = PyGetString(buffer.buffer_info()[0], buffer_len - 1) return text
Example #21
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __call__(self): if self.plugin.runFlg and self.plugin.mpcHwnd: wx.CallAfter(SendMessage,self.plugin.mpcHwnd, WM_COMMAND, self.value, 0) #===============================================================================
Example #22
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __call__(self, osd="", dur=3, pos=1): if self.plugin.mpcHwnd is not None: osd = eg.ParseString(osd) + "\0" OSDDATA.nMsgPos = pos OSDDATA.nDurationMS = 1000*dur OSDDATA.strMsg = osd.encode(eg.systemEncoding) cds = COPYDATASTRUCT() cds.dwData = CMD_OSDSHOWMESSAGE cds.cbData = sizeof(OSDDATA) cds.lpData = cast(addressof(OSDDATA), c_void_p) SendMessage(self.plugin.mpcHwnd, WM_COPYDATA, 0, addressof(cds))
Example #23
Source File: winguiauto.py From pyAutoTrading with GNU General Public License v2.0 | 5 votes |
def _readListViewItems(hwnd, column_index=0): # Allocate virtual memory inside target process pid = ctypes.create_string_buffer(4) p_pid = ctypes.addressof(pid) GetWindowThreadProcessId(hwnd, p_pid) # process owning the given hwnd hProcHnd = OpenProcess(win32con.PROCESS_ALL_ACCESS, False, struct.unpack("i", pid)[0]) pLVI = VirtualAllocEx(hProcHnd, 0, 4096, win32con.MEM_RESERVE | win32con.MEM_COMMIT, win32con.PAGE_READWRITE) pBuffer = VirtualAllocEx(hProcHnd, 0, 4096, win32con.MEM_RESERVE | win32con.MEM_COMMIT, win32con.PAGE_READWRITE) # Prepare an LVITEM record and write it to target process memory lvitem_str = struct.pack('iiiiiiiii', *[0, 0, column_index, 0, 0, pBuffer, 4096, 0, 0]) lvitem_buffer = ctypes.create_string_buffer(lvitem_str) copied = ctypes.create_string_buffer(4) p_copied = ctypes.addressof(copied) WriteProcessMemory(hProcHnd, pLVI, ctypes.addressof(lvitem_buffer), ctypes.sizeof(lvitem_buffer), p_copied) # iterate items in the SysListView32 control num_items = win32gui.SendMessage(hwnd, commctrl.LVM_GETITEMCOUNT) item_texts = [] for item_index in range(num_items): win32gui.SendMessage(hwnd, commctrl.LVM_GETITEMTEXT, item_index, pLVI) target_buff = ctypes.create_string_buffer(4096) ReadProcessMemory(hProcHnd, pBuffer, ctypes.addressof(target_buff), 4096, p_copied) item_texts.append(target_buff.value) VirtualFreeEx(hProcHnd, pBuffer, 0, win32con.MEM_RELEASE) VirtualFreeEx(hProcHnd, pLVI, 0, win32con.MEM_RELEASE) win32api.CloseHandle(hProcHnd) return item_texts
Example #24
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def getListboxItems(self, hwnd): if self.only_sel: num_selected = win32guiSendMessage(hwnd, LB_GETSELCOUNT, 0, 0) if num_selected == LB_ERR: # if we got LB_ERR then it is a single selection list box items = (win32guiSendMessage(hwnd, LB_GETCURSEL, 0, 0), ) else: # otherwise it is a multiselection list box items = (c_int * num_selected)() win32guiSendMessage(hwnd, LB_GETSELITEMS, num_selected, addressof(items)) items = tuple(items) # Convert from Ctypes array to a python tuple else: items = None return self.getMultipleValues(hwnd, LB_GETCOUNT, LB_GETTEXT, items)
Example #25
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def getMultipleValues(self, hwnd, CountMessg, ValMessg, selected = None): buf_size = 512 buf = create_string_buffer(pack_int(buf_size), buf_size) indexes = selected if selected else range(win32guiSendMessage(hwnd, CountMessg, 0, 0)) val = [] for ix in indexes: valLngth = win32guiSendMessage(hwnd, ValMessg, ix, addressof(buf)) val.append(buf.value[:valLngth].decode(eg.systemEncoding)) return val
Example #26
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def MonitorState(state): if state == 'ON': ctypes.windll.user32.mouse_event(MOUSEEVENTF_MOVE, 0, 1, 0, 0) else: win32gui.SendMessage( win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_STATES[state] )
Example #27
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __call__(self): SendMessage(GetForegroundWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0) #----------------------------------------------------------------------------- # Image actions #-----------------------------------------------------------------------------
Example #28
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def controlMeedio(inputVal): try: hMeedioWnd = win32gui.FindWindow('H2-WM-COMMAND', None) return win32gui.SendMessage(hMeedioWnd, 273, inputVal, 0) except Exception: pass
Example #29
Source File: winapi.py From gui-o-matic with GNU Lesser General Public License v3.0 | 5 votes |
def set_font( self, font ): win32gui.SendMessage( self.handle, win32con.WM_SETFONT, font, True )
Example #30
Source File: winapi.py From gui-o-matic with GNU Lesser General Public License v3.0 | 5 votes |
def set_range( self, value ): win32gui.SendMessage( self.handle, commctrl.PBM_SETRANGE, 0, win32api.MAKELONG( 0, value ) )