def __init__(self, title): self.title = title (self.left, self.top, self.right, self.bottom) = win32ui.FindWindow(None, title).GetWindowRect() self.hwin = win32ui.FindWindow(None, title).GetSafeHwnd() self.shell = win32com.client.Dispatch("WScript.Shell") self.shell.AppActivate(title)
def WindowExists(classname=None, windowname=None): try: win32ui.FindWindow(None, windowname) if windowname else win32ui.FindWindow(classname, None) if classname else None return True except win32ui.error: try: win32ui.FindWindow(classname, None) if classname else win32ui.FindWindow(None, windowname) if windowname else None return True except: return False return False
def isWindowOpen(classname, classname2): try: win32ui.FindWindow(classname, classname2) except win32ui.error: return False else: return True
def hookhandle(event): if event.KeyID == 9: # tab键值 try: pwin = win32ui.FindWindow( 'AfxMDIFrame70', None) # 主窗口 AfxMDIFrame70就是你用#spyxx.exe查找到的窗口类名 pwin1 = win32ui.FindWindowEx(pwin, None, 'MDIClient', None) pwin2 = win32ui.FindWindowEx(pwin1, None, 'AfxFrameOrView70', None) pwin3 = win32ui.FindWindowEx(pwin2, None, "AfxOleControl70", None) pwin4 = win32ui.FindWindowEx( pwin3, None, None, "PatientCardControl Frame" ) # 可以根据窗口#的标题名称查找 标题名称一般外接程序是不变的 而类名有时是变化的 比如机器重启 关闭等 pwin5 = win32ui.FindWindowEx(pwin4, None, "AfxMDIFrame70", None) pwin6 = win32ui.FindWindowEx(pwin5, None, "AfxWnd70", None) pwin7 = win32ui.FindWindowEx(pwin6, None, "#32770", None) textbox = pwin7.GetDlgItem(222) # 获取控件的ID textbox2 = pwin7.GetDlgItem(224) buf = '0x0' * 1024 buf2 = '0x0' * 1024 textbox.SendMessage(win32con.WM_SETTEXT, "") # 先清空控件内容 textbox2.SendMessage(win32con.WM_SETTEXT, "") oldlen = textbox.SendMessage(win32con.WM_GETTEXT, buf) oldlen2 = textbox2.SendMessage(win32con.WM_GETTEXT, buf2) textbox.SendMessage(win32con.WM_SETTEXT, buf[0:oldlen] + str(blh)) # 发送消息 注意不能##用%s 替换 所以一般需要全局变量 来替换 textbox2.SendMessage(win32con.WM_SETTEXT, buf2[0:oldlen] + str(name)) except: wx.LogMessage('没有发现可用的窗口!请确保程序已经运行')
def WindowExists(title): try: win32ui.FindWindow(None, title) except win32ui.error: return False else: return True
def outlook_is_running(): import win32ui try: win32ui.FindWindow(None, "Microsoft Outlook") return True except win32ui.error: return False
def hWnd(self): """ 控制台窗口句柄 """ # ----------------------------------- # 通过 win32ui 获取窗口句柄 # ----------------------------------- win32ui = None try: import win32ui # 如果完全打包,将找不到 win32ui(还不知道什么原因) except: pass hCmdWnd = -1 if win32ui is not None: try: cmdWnd = win32ui.FindWindow(None, self.__title) hCmdWnd = cmdWnd.GetSafeHwnd() # 控制台所属窗口句柄 except: pass if hCmdWnd > 0: return hCmdWnd # ----------------------------------- # ----------------------------------- # 通过 winappdbg 库获取窗口句柄 # ----------------------------------- from winappdbg import win32 try: hCmdWnd = win32.user32.FindWindowA(None, self.__title) except Exception, err: try: hCmdWnd = win32.user32.FindWindowW(None, self.__title) except: pass
def __init__(self, windowName, windowName2=''): Context.i = self self.lock = threading.Lock() try: self.window = win.FindWindow(None, windowName) except: if windowName2 != '': windowName = windowName2 else: windowName = self.getForegroundWindow() self.window = win.FindWindow(None, windowName) print('context:', windowName) self.x, self.y, self.x2, self.y2 = wgui.GetWindowRect(wgui.FindWindow(None, windowName)) self.w = self.x2 - self.x self.h = self.y2 - self.y
def is_running() -> bool: """Return true if Outlook is running""" try: win32ui.FindWindow(None, 'Microsoft Outlook') return True except win32ui.error: return False
def WindowExists(classname): try: win32ui.FindWindow(classname, None) except win32ui.error: return False else: return True
def getPixelColor(x, y): name = "Minesweeper Online - Play Free Online Minesweeper - Google Chrome" #just an example of a window I had open at the time w = win32ui.FindWindow( None, name ) dc = w.GetWindowDC() toReturn = dc.GetPixel(x, y) dc.DeleteDC() return toReturn
def window_exists(classname, windowname): try: win32ui.FindWindow(classname, windowname) except win32ui.error: return False else: return True
def _select_file(self, title, directory, filename, patterns, extension, save, multi): import win32ui import win32con flags = win32con.OFN_HIDEREADONLY if save: flags |= win32con.OFN_OVERWRITEPROMPT mode = 0 else: mode = 1 if multi: flags |= win32con.OFN_ALLOWMULTISELECT # This hack with finding non-specified windows is used so that # we get some parent window for CreateFileDialog. # Without this parent windows the method DoModal doesn't show # the dialog window on top... parent = win32ui.FindWindow(None, None) dialog = win32ui.CreateFileDialog(mode, extension, "%s" % filename or '*.*', flags, '|'.join(["%s|%s" % (self._pattern_label(label, pat), ';'.join(pat)) for label, pat in patterns]) + '||', parent) if directory: dialog.SetOFNInitialDir(directory) result = dialog.DoModal() if result != 1: return None if multi: return dialog.GetPathNames() else: return dialog.GetPathName()
def game_running(): try: win32ui.FindWindow('Valve001', 'Counter-Strike: Global Offensive') except win32ui.error: return False else: return True
def WindowExists(): try: win32ui.FindWindow(None, "Zoom Meeting") except win32ui.error: return False else: return True
def postMessage(self, msg, wparam, lparam): hwnd = win32ui.FindWindow( None, "S60 3rd Edition SDK, for C++ [352x416] - winscw udeb") if hwnd != 0: hwnd.PostMessage(msg, wparam, lparam) else: print "window not found"
def _get_pageant_window_object(): try: hwnd = win32ui.FindWindow('Pageant', 'Pageant') return hwnd except win32ui.error: pass return None
def _find_agent_window(): """Find and return the Pageant window""" try: return win32ui.FindWindow(_AGENT_NAME, _AGENT_NAME) except win32ui.error: raise OSError(errno.ENOENT, 'Agent not found') from None
def checkifMeshMixerRunning(): try: win32ui.FindWindow("QWidget", None) return True except: print 'meshmixer isnt open' return False
def connect_photoshop(self): try: if win32ui.FindWindow('Photoshop', None) != None: try: '''COM dispatch for Photoshop''' self.ps_app = win32com.client.Dispatch( 'Photoshop.Application') self.options = win32com.client.Dispatch( 'Photoshop.TargaSaveOptions') self.options.Resolution = 24 self.options.AlphaChannels = False self.options.RLECompression = False self.ps_app.Preferences.RulerUnits = 1 except: self.message_report( error_level=2, message= "Cannot connect to Photoshop! Make sure all Photoshop option windows are closed!" ) except: self.message_report( error_level=2, message="Cannot find a Photoshop window to connect!")
def Prepare(self, test): recorder = test.GetRecorder() file_base = test.GetFileBase() if recorder is not None and file_base is not None: args = [recorder, '--filebase', file_base, '--histograms'] if test.TcpDump(): args.append('--tcpdump') args.append('--video') if test.FullSizeVideo(): args.append('--noresize') args.extend(['--quality', str(test.GetImageQuality())]) try: self.proc = subprocess.Popen(args) except: logging.debug('Error launching recorder "{0}"'.format(recorder)) # Wait for the recorder window to be available for 30 seconds start = time.time() while self.window is None and time.time() - start < 30: try: self.window = win32ui.FindWindow("wptRecord", "wptRecord") except: time.sleep(0.1) if self.window is not None: try: self.window.SendMessage(self.UWM_PREPARE, 0, 0) except: pass
def initContext(emu): if cd.lock == None: cd.lock = threading.Lock() cd.emuWindow = win.FindWindow(None, emu) cd.context = cd.emuWindow.GetWindowDC() cd.winX, cd.winY, cd.winX2, cd.winY2 = wgui.GetWindowRect( wgui.FindWindow(None, emu)) cd.context.DeleteDC()
def League_Running(): if win32ui.FindWindow(None, "League of Legends (TM) Client"): return True else: print("Client window not found") return False
def flush(padding=1): # Send the flush key. # _SHELL.AppActivate('Counter-Strike: Global Offensive') # _SHELL.SendKeys('{%s}' % FLUSH_KEY, 0) window = win32ui.FindWindow('Valve001', 'Counter-Strike: Global Offensive') time.sleep(padding) clear()
def blocking_window_open(): try: for classname in BLOCKING_WINDOW_CLASSES: win32ui.FindWindow(classname, None) except win32ui.error: return False else: return True
def exposed_open_selected_file(self, template=None, encrypt=None): """Return a read-only 'file' like object of a user selected file. The file is selected by the user using a GUI dialog. If the user cancels the dialog, 'None' is returned. Arguments: template -- a string defining the required file name pattern, or 'None' encrypt -- list of encryption keys to use to encrypt the file; if the list is empty then let the user select the keys; if 'None' then don't encrypt the file """ assert template is None or isinstance(template, basestring), template if self._pytis_on_windows(): import win32ui import win32con extension = None if template: file_filter = (u"Soubory požadovaného typu (%s)|%s|Všechny soubory (*.*)|*.*||" % (template, template,)) filename = template if template.find('.') != -1: extension = template.split('.')[-1] else: file_filter = u"Všechny soubory (*.*)|*.*||" filename = "*.*" parent = win32ui.FindWindow(None, None) flags = win32con.OFN_HIDEREADONLY | win32con.OFN_OVERWRITEPROMPT dialog = win32ui.CreateFileDialog(1, extension, "%s" % filename, flags, file_filter, parent) result = dialog.DoModal() if result != 1: return None filename = unicode(dialog.GetPathName(), sys.getfilesystemencoding()) else: filename = self._pytis_file_dialog(template=template) if filename is None: return None if encrypt is not None: gpg = self._gpg() keys = self._select_encryption_keys(gpg, encrypt) class Wrapper(object): def __init__(self, filename): f = open(filename, 'rb') if encrypt is not None: s = gpg.encrypt_file(f, keys) f = cStringIO.StringIO(str(s)) self._f = f self._filename = filename def exposed_read(self): return self._f.read() def exposed_close(self): self._f.close() def exposed_name(self): return self._filename return Wrapper(filename)
def exposed_make_selected_file(self, directory=None, filename=None, template=None, encoding=None, mode='wb', decrypt=False): """Return a write-only 'file' like object of a user selected file. The file is selected by the user using a GUI dialog. If the user cancels the dialog, 'None' is returned. Arguments: directory -- initial directory for the dialog filename -- default filename or None template -- a string defining the required file name pattern, or 'None' encoding -- output encoding, string or None mode -- default mode for opening the file decrypt -- if true then decrypt the file contents """ assert template is None or isinstance(template, basestring), template if self._pytis_on_windows(): import win32ui import win32con file_filter = u"Všechny soubory (*.*)|*.*||" extension = None if filename: name, ext = os.path.splitext(filename) if ext: template = "*" + ext file_filter = (u"Soubory požadovaného typu (%s)|%s|%s" % (template, template, file_filter)) extension = ext[1:] else: filename = "*.*" if template: file_filter = (u"Soubory požadovaného typu (%s)|%s|%s" % (template, template, file_filter)) # This hack with finding non-specified windows is used so that # we get some parent window for CreateFileDialog. # Without this parent windows the method DoModal doesn't show # the dialog window on top... parent = win32ui.FindWindow(None, None) flags = win32con.OFN_HIDEREADONLY | win32con.OFN_OVERWRITEPROMPT dialog = win32ui.CreateFileDialog(0, extension, "%s" % filename, flags, file_filter, parent) if directory: dialog.SetOFNInitialDir(directory) result = dialog.DoModal() if result != 1: return None filename = dialog.GetPathName() if filename is None: return None filename = unicode(filename, sys.getfilesystemencoding()) else: filename = self._pytis_file_dialog(directory=directory, filename=filename, template=template, save=True) if filename is None: return None return self._open_file(filename, encoding, mode, decrypt=decrypt)
def outlook_is_running(): import win32ui try: win32ui.FindWindow(None, "Microsoft Outlook") print("Outlook already running") return True except win32ui.error: print("Outlook is not running") return False
def outlook_running(): """This function checks whether or not Microsoft Outlook is open.""" try: win32ui.FindWindow(None, "Microsoft Outlook") return True except win32ui.error: return False
def WindowExists(self, classname): import win32ui try: win32ui.FindWindow(None, classname) except win32ui.error as e: print(str(e)) return False else: return True