def OnShowPos(self, hwnd, msg, wparam, lparam): ctrl = win32gui.GetDlgItem(self.hwnd, IDC_SEARCHTEXT) s = str(win32api.HIWORD(wparam)) + ', ' + str(win32api.LOWORD(wparam)) s += " " s += str(win32api.HIWORD(lparam)) + ', ' + str(win32api.LOWORD(lparam)) win32gui.SetWindowText(ctrl, s) ctrl2 = win32gui.GetDlgItem(self.hwnd, IDC_STATUS) s = str(win32api.HIWORD(lparam) - win32api.HIWORD(wparam)) + ', ' + str( win32api.LOWORD(lparam) - win32api.LOWORD(wparam)) win32gui.SetWindowText(ctrl2, s)
def title(self): base = "CSDBot: [F1 - QUIT / F2 - PAUSE / F3 - EDIT]" if self.is_terminated: print(f"[!] Bye!") win32gui.SetWindowText(self.hwnd, "Cook, Serve, Delicious!") sys.exit(0) elif self.is_paused: win32gui.SetWindowText(self.hwnd, f"{base} ~ Paused") elif self.is_editing: win32gui.SetWindowText( self.hwnd, f"{base} ~ {self.Brain.lastUnknown}: {self.edit_stack}") else: win32gui.SetWindowText(self.hwnd, f"{base}{self.Brain.status()}")
def login(self, user_name, user_pwd, room_id, front_server="192.168.7.185:1089"): commandline = "%s -uname %s -upwd %s -rid %s -utype 1 -link TCP:%s -stype 1"%\ (os.path.join(self.client_path,"FastMeeting.exe"),user_name,user_pwd,room_id,front_server) subprocess.Popen(commandline) while self.hwnd == 0: time.sleep(5) classname = "CMainDlg" titlename = u"好视通云会议" self.hwnd = win32gui.FindWindow(classname, titlename) print self.hwnd win32gui.SetWindowText(self.hwnd, self.client_flag) rect = (0, 0, 0, 0) i = 0 while rect[2] - rect[0] <= 929: if i > 60: raise Exception('login outtime') time.sleep(1) rect = win32gui.GetWindowRect(self.hwnd) i += 1 win32gui.MoveWindow(self.hwnd, 0, 0, 929, 694, 0) time.sleep(1) ret = self.dm.BindWindowEx(self.hwnd, "gdi2", "windows", "windows", "", 0) if ret == 0: raise Exception("BindWindow Error") time.sleep(3)
def open_CLI(title, pos): if 1: p = Popen(["cmd.exe"], creationflags=CREATE_NEW_CONSOLE) if 1: if 1: hwnd = None while not hwnd: hwnd = get_hwnds_for_pid(p.pid) #print (hwnd) assert hwnd win = hwnd[0] #print(window1) if 0: (x, y) = win.GetScreenPosition() print('GetScreenPosition: ', x, y) (l, w) = win.GetClientSize() print('GetClientSize: ', l, w) dl, dw = win.GetSize() print('GetSize:', dl, dw) if 1: win32gui.SetWindowText(win, title) win32gui.SetForegroundWindow(win) win32gui.MoveWindow(win, *pos, True) return win
def clear_log(): # Function to clear status window. # Natlink status window not used an out-of-process mode. # TODO: window_exists utilized when engine launched through Dragonfly CLI via bat in future try: if WIN32: clearcmd = "cls" # Windows OS else: clearcmd = "clear" # Linux if get_current_engine().name == 'natlink': import natlinkstatus # pylint: disable=import-error status = natlinkstatus.NatlinkStatus() if status.NatlinkIsEnabled() == 1: import win32gui # pylint: disable=import-error handle = get_window_by_title( "Messages from Python Macros") or get_window_by_title( "Messages from Natlink") rt_handle = win32gui.FindWindowEx(handle, None, "RICHEDIT", None) win32gui.SetWindowText(rt_handle, "") else: if window_exists(windowname="Caster: Status Window"): os.system(clearcmd) else: if window_exists(windowname="Caster: Status Window"): os.system(clearcmd) else: printer.out("clear_log: Not implemented with GUI") except Exception as e: printer.out(e)
def window_title_set(window=None, new_title: str = '') -> int: ''' Sets window title, returns hwnd. ''' hwnd = window_get(window) if hwnd: win32gui.SetWindowText(hwnd, new_title) return hwnd
def show_window(self): """ Show the change time dialog window """ if self.hwnd is None: self.__create_window() else: win32gui.BringWindowToTop(self.hwnd) win32gui.SetWindowText( win32gui.GetDlgItem(self.hwnd, self.resources.ids['IDC_HOURS']), str(int(self.minutes / 60))) win32gui.SetWindowText( win32gui.GetDlgItem(self.hwnd, self.resources.ids['IDC_MINUTES']), str(self.minutes % 60))
def open_app_overlay(faceit_name): height = config_functions.check_for_layout() hwnd = win32gui.GetForegroundWindow() win32gui.MoveWindow(hwnd, 0, 0, 208, height[0] + 39, True) simple.hide_item("##Overlay") simple.hide_item("##Config") win32gui.SetWindowText(hwnd, f"{faceit_name} Elo") eloOverlay.show_main()
def title_countdown(hwnd:int, timeout:int, title:str): for sec in reversed(range(100 * (timeout // 1000) ) ): try: win32gui.SetWindowText( hwnd , f'[{sec // 100 + 1}] {title}' ) except: break time.sleep(0.01)
def set_time(self, minutes): """ Set the current logged number of minutes :param minutes: Number of minutes """ self.minutes = minutes if self.hwnd is not None: win32gui.SetWindowText( win32gui.GetDlgItem(self.hwnd, self.resources.ids['IDC_HOURS']), str(int(self.minutes / 60))) win32gui.SetWindowText( win32gui.GetDlgItem(self.hwnd, self.resources.ids['IDC_MINUTES']), str(self.minutes % 60)) if self.time_changed_callback is not None: self.time_changed_callback(minutes)
def switch_back_to_menu(): logging.info("Switch back to start menu") global start_threading start_threading = 0 hwnd = win32gui.GetForegroundWindow() win32gui.MoveWindow(hwnd, 0, 0, 492, 830, True) simple.show_item("##Overlay") simple.show_item("##Config") faceit_name = config_functions.get_faceit_name_from_db() core.delete_item(f"{faceit_name} Elo") win32gui.SetWindowText(hwnd, "FACEIT Elo Overlay")
def enumHandlerMove(hwnd, lParam): old_name = lParam['old_name'] coords = lParam['coords'] new_name = lParam['name'] size = lParam['size'] if win32gui.IsWindowVisible(hwnd): if old_name in win32gui.GetWindowText(hwnd): win32gui.MoveWindow(hwnd, coords[0], coords[1], size[0], size[1], True) win32gui.SetWindowText(hwnd, new_name) print("Moved window: %s" % hwnd)
def UpdateControl_FromValue(self): name_val = self.GetOptionValue(self.option_folder_name) id_val = self.GetOptionValue() self.in_setting_name = True if id_val: self.SetOptionValue("", self.option_folder_name) opt_processors.FolderIDProcessor.UpdateControl_FromValue(self) else: if name_val: win32gui.SetWindowText(self.GetControl(), name_val) self.in_setting_name = False
def changeControls(self): win32gui.EnableWindow(self.back_btn_hwnd, self.currentPageIndex != 0) if self.canGoNext(): enabled = 1 else: enabled = 0 win32gui.EnableWindow(self.forward_btn_hwnd, enabled) index = 0 if self.atFinish(): index = 1 win32gui.SetWindowText(self.forward_btn_hwnd, self.forward_captions[index])
def OpenCliAndSendPayload(pld, title, pos): win = open_CLI(title, pos) sleep(0.2) if 1: win32gui.SetWindowText(win, title) sleep(0.2) for i, p in enumerate(pld): win32gui.SetForegroundWindow(win) send_str(win, p)
def next_candidate(self, dir): text = win32gui.GetWindowText(self.hwnd_edit) selinfo = win32gui.SendMessage(self.hwnd_edit, win32con.EM_GETSEL, 0, 0) endpos = win32api.HIWORD(selinfo) startpos = win32api.LOWORD(selinfo) unselected_text = text[:startpos] proposals = self.cmds.proposals(unselected_text) win32gui.SetWindowText( self.hwnd_edit, proposals[(proposals.index(text) + dir) % len(proposals)]) win32api.SendMessage(self.hwnd_edit, win32con.EM_SETSEL, len(unselected_text), -1)
def _rename_windows(self): gui.EnumWindows(self._enum_windows_handle, self.hwnd_list) # Associate window_handle for hwnd in self.hwnd_list: _, proc_id = proc.GetWindowThreadProcessId(hwnd) acc_idx = self.process_acc_idx.get(proc_id, None) if acc_idx is None: continue # Fix for finding false positives wow windows new_title = f"{TITLE_PREFIX}{acc_idx}" gui.SetWindowText(hwnd, new_title) self.acc_idx_hwnd[acc_idx] = hwnd
def flush_window(self): ''' 刷新窗口并将窗口队列中的所有窗口取消 如果需要对窗口操作,需要重新调用findWindows() :return: ''' self.main_window = None for window in self.windows_handles: try: win32gui.SetWindowText(window['handle'], window['title']) except pywintypes.error as e: continue self.windows_handles.clear()
def rename_wows(process_acc_idx): hwnd_list = [] gui.EnumWindows(enum_windows_handler, hwnd_list) # Associate window_handle with process_id and rename window\ for hwnd in hwnd_list: _, process_id = proc.GetWindowThreadProcessId(hwnd) acc_idx = process_acc_idx[process_id] new_title = f"{TITLE_PREFIX}{acc_idx}" gui.SetWindowText(hwnd, new_title) # Store hwnd for acc_idx acc_idx_hwnd[acc_idx] = hwnd
def show(self): x, y = win32gui.GetCursorPos() win32gui.MoveWindow(self.hwnd, x, y, 256, 96, True) win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW) win32gui.SetWindowText(self.hwnd_edit, "") win32gui.SetForegroundWindow(self.hwnd) base_path = os.path.dirname(__file__) with codecs.open(os.path.join(base_path, 'winhk_config.py'), encoding='utf-8') as f: s = f.read() self.cmds = CommandList() exec(compile(s, 'winhk_config.py', 'exec'), globals(), self.cmds)
def clear_log(): # Function to clear natlink status window try: # pylint: disable=import-error import natlink windows = Window.get_all_windows() matching = [w for w in windows if b"Messages from Python Macros" in w.title] if matching: handle = (matching[0].handle) rt_handle = win32gui.FindWindowEx(handle, None, "RICHEDIT", None) win32gui.SetWindowText(rt_handle, "") return except Exception as e: printer.out(e)
def findWindows(self): '''查找游戏窗口''' while True: handle = win32gui.FindWindow(CLASSNAME, WINDOWNAME) if handle: title = win32gui.GetWindowText(handle) pid = win32process.GetWindowThreadProcessId(handle) self.windows_handles.append({ 'title': title, 'handle': handle, 'pid': pid }) win32gui.SetWindowText(handle, f"{title} - pid:{pid[-1]}") else: break
def assWindow(): j = 0 for i in range(len(windows)): win32gui.MoveWindow(windows[j][0], 500, 0, 1000, 500, True) # win32gui.ShowWindow(windows[1][0], 0) #win32gui.BringWindowToTop(windows[0][0]) print(win32gui.IsWindowVisible(windows[0][0])) win32gui.SetWindowText(windows[j][0], 'Taken over your window') #win32gui.CreateWindow('theNEWNEW', 'BESTEST_WINDOW_EVER', 0, 200, 200, 500, 500, 0, 0, 0, 0) j = j + 1
def UpdateControl_FromValue(self): # Set the static to folder names mgr = self.window.manager if self.option.multiple_values_allowed(): ids = self.GetOptionValue() else: ids = [self.GetOptionValue()] names = [] for eid in ids: if eid is not None: try: folder = mgr.message_store.GetFolder(eid) if self.use_fqn: name = folder.GetFQName() else: name = folder.name except mgr.message_store.MsgStoreException: name = "<unknown folder>" names.append(name) win32gui.SetWindowText(self.GetControl(), self.name_joiner.join(names))
def wndproc(hwnd, msg, wParam, lParam): # FIXME: not print()ing in wndproc mysteriously cause "OSError: exception: access violation" print("MW: %08x %08x %08x" % (msg, wParam, lParam)) if msg == win32con.WM_COMMAND and win32api.HIWORD( wParam) == win32con.EN_CHANGE: text = win32gui.GetWindowText(self.hwnd_edit) if len(text) == 0: return 0 proposals = self.cmds.proposals(text) if not proposals: return 0 win32gui.SetWindowText(self.hwnd_edit, proposals[0]) win32api.SendMessage(self.hwnd_edit, win32con.EM_SETSEL, len(text), -1) if msg == win32con.WM_SETFOCUS: win32gui.SetFocus(self.hwnd_edit) windll.user32.DefWindowProcW.argtypes = (ctypes.wintypes.HWND, ctypes.wintypes.UINT, ctypes.wintypes.WPARAM, ctypes.wintypes.LPARAM) return windll.user32.DefWindowProcW(hwnd, msg, wParam, lParam)
def OpenApp(dir, pld, pos, title): global home if 1: os.chdir(dir) p = Popen(["cmd.exe", '/c'] + pld, creationflags=CREATE_NEW_CONSOLE) os.chdir(home) if 1: if 1: hwnd = None while not hwnd: hwnd = get_hwnds_for_pid(p.pid) #print (hwnd) assert hwnd win = hwnd[0] #print(window1) if 0: (x, y) = win.GetScreenPosition() print('GetScreenPosition: ', x, y) (l, w) = win.GetClientSize() print('GetClientSize: ', l, w) dl, dw = win.GetSize() print('GetSize:', dl, dw) if 1: win32gui.SetWindowText(win, title) win32gui.SetForegroundWindow(win) win32gui.MoveWindow(win, *pos, True) if 1: rect = win32gui.GetWindowRect(win) x = rect[0] y = rect[1] w = rect[2] - x h = rect[3] - y print("Window %s:" % win32gui.GetWindowText(win)) print("\tLocation: (%d, %d)" % (x, y)) print("\t Size: (%d, %d)" % (w, h)) return win, (x, y, w, h)
def OpenPuttyAndSendPayload(pld, host, user, pwd, title, pos=[150, 100, 1200, 800]): global putty_loc win = OpenPutty(putty_loc, host=host, user=user, pwd=pwd, pos=pos) sleep(1) if 1: win32gui.SetWindowText(win, title) sleep(1) if 1: rect = win32gui.GetWindowRect(win) x = rect[0] y = rect[1] w = rect[2] - x h = rect[3] - y print("Window %s:" % win32gui.GetWindowText(win)) print("\tLocation: (%d, %d)" % (x, y)) print("\t Size: (%d, %d)" % (w, h)) #win32gui.EnumWindows(callback, None) #e(0) win32gui.SetForegroundWindow(win) sleep(0.2) send_str(win, 'bash\n') sleep(0.2) for i, p in enumerate(pld): #print(i,p) #time.sleep(.1) win32gui.SetForegroundWindow(win) send_str(win, p) if p.startswith(pwd): sleep(1) return win, (x, y, w, h)
def OpenPuttyAndSendPayload(pld, host, user, pwd, title, pos=[150, 100, 12000, 800]): global putty_loc win=OpenPutty(putty_loc, host=host, user=user, pwd=pwd, pos=pos) sleep(1) if 1: win32gui.SetWindowText(win, title) win32gui.SetForegroundWindow(win) sleep(0.2) send_str( win, 'bash\n') sleep(0.2) for i,p in enumerate(pld): #print(i,p) #time.sleep(.1) win32gui.SetForegroundWindow(win) send_str( win, p) if p.startswith(pwd): sleep(1) return win
def SetWindowText(self, hwnd, title): try: if hwnd == None: return None return win32gui.SetWindowText(hwnd, title) except win32gui.error: return None
def msgbox(msg:str, title:str=None , ui:int=None, wait:bool=True, timeout=None , dis_timeout:float=None)->int: ''' wait - msgbox should be closed to continue task ui - combination of buttons and icons timeout - timeout in seconds (int) or str with unit: '5 sec', '5 min', '2 hour' etc dis_timeout (seconds) - disable buttons for x seconds. Should be smaller than timeout. ''' def get_hwnd(title_tmp:str): hwnd = 0 for _ in range(1000): hwnd = win32gui.FindWindow(None, title_tmp) if hwnd: break return hwnd def title_countdown(hwnd:int, timeout:int, title:str): for sec in reversed(range(100 * (timeout // 1000) ) ): try: win32gui.SetWindowText( hwnd , f'[{sec // 100 + 1}] {title}' ) except: break time.sleep(0.01) def dis_buttons(hwnd:int, dis_timeout:float): def dis_butt(hchild, state): if win32gui.GetWindowLong(hchild, -12) < 12: win32gui.ShowWindow(hchild, state) return True time.sleep(0.01) try: win32gui.EnumChildWindows(hwnd, dis_butt, False) time.sleep(dis_timeout) win32gui.EnumChildWindows(hwnd, dis_butt, True) except: pass title = _get_parent_func_name(title) if ui: ui += win32con.MB_SYSTEMMODAL else: ui = win32con.MB_ICONINFORMATION + win32con.MB_SYSTEMMODAL if timeout: mb_func = _MessageBoxTimeout title_tmp = title + ' rand' + str(random.randint(100000, 1000000)) timeout = int( value_to_unit(timeout, 'ms') ) mb_args = (None, msg, title_tmp, ui, 0, timeout) else: if dis_timeout: mb_func = _MessageBox title_tmp = title + ' rand' + str(random.randint(100000, 1000000)) mb_args = (None, msg, title_tmp, ui) else: mb_func = _MessageBox mb_args = (None, msg, title, ui) if wait: if timeout: result = [] threading.Thread( target=lambda *a, r=result: r.append(mb_func(*a)) , args=mb_args , daemon=True ).start() hwnd = get_hwnd(title_tmp) if hwnd: if dis_timeout: threading.Thread( target=dis_buttons , args=(hwnd, dis_timeout,) , daemon=True ).start() threading.Thread( target=title_countdown , args=(hwnd, timeout, title,) , daemon=True ).start() while not result: time.sleep(0.01) if result: return result[0] else: return 0 else: if dis_timeout: result = [] threading.Thread( target=lambda *a, r=result: r.append(mb_func(*a)) , args=mb_args , daemon=True ).start() hwnd = get_hwnd(title_tmp) if hwnd: win32gui.SetWindowText(hwnd, title) threading.Thread( target=dis_buttons , args=(hwnd, dis_timeout,) , daemon=True ).start() while not result: time.sleep(0.01) return result[0] else: return mb_func(*mb_args) else: if timeout: if dis_timeout: threading.Thread( target=mb_func , args=mb_args , daemon=True ).start() hwnd = get_hwnd(title_tmp) if hwnd: win32gui.SetWindowText(hwnd, title) threading.Thread( target=dis_buttons , args=(hwnd, dis_timeout,) , daemon=True ).start() threading.Thread( target=title_countdown , args=(hwnd, timeout, title) , daemon=True ).start() else: threading.Thread( target=mb_func , args=mb_args , daemon=True ).start() hwnd = get_hwnd(title_tmp) if hwnd: win32gui.SetWindowText(hwnd, title) threading.Thread( target=title_countdown , args=(hwnd, timeout, title,) , daemon=True ).start() else: if dis_timeout: threading.Thread( target=mb_func , args=mb_args , daemon=True ).start() hwnd = get_hwnd(title_tmp) if hwnd: win32gui.SetWindowText(hwnd, title) threading.Thread( target=dis_buttons , args=(hwnd, dis_timeout,) , daemon=True ).start() else: threading.Thread( target=mb_func , args=mb_args , daemon=True ).start()