def Find(self): winClassMatch = self.winClassMatch winNameMatch = self.winNameMatch programMatch = self.programMatch includeInvisible = self.includeInvisible topWindowsHwnds = [ hwnd for hwnd in GetTopLevelWindowList(includeInvisible) if ( winClassMatch(GetClassName(hwnd)) and winNameMatch(GetWindowText(hwnd)) ) ] if self.program: topWindowsHwnds = [ hwnd for hwnd in topWindowsHwnds if programMatch(GetWindowProcessName(hwnd).upper()) ] if not self.scanChilds: return topWindowsHwnds childClassMatch = self.childClassMatch childNameMatch = self.childNameMatch childHwnds = [ childHwnd for parentHwnd in topWindowsHwnds for childHwnd in GetWindowChildsList( parentHwnd, includeInvisible ) if ( childClassMatch(GetClassName(childHwnd)) and childNameMatch(GetWindowText(childHwnd)) ) ] return childHwnds
def AppendChildWindows(self, parentHwnd, item): for hwnd in GetHwndChildren(parentHwnd, self.includeInvisible): name = GetWindowText(hwnd) className = GetClassName(hwnd) if name != "": name = "\"" + name + "\" " index = self.AppendItem(item, name + className, 0) self.SetPyData(index, hwnd) if className == "Edit" or className == "TEdit": self.SetItemImage(index, 1, which=wx.TreeItemIcon_Normal) elif className == "Static" or className == "TStaticText": self.SetItemImage(index, 2, which=wx.TreeItemIcon_Normal) elif className == "Button" or className == "TButton": self.SetItemImage(index, 3, which=wx.TreeItemIcon_Normal) elif GetClassName(parentHwnd) == "MDIClient": icon = GetHwndIcon(hwnd) if icon: iconIndex = self.imageList.AddIcon(icon) self.SetItemImage( index, iconIndex, which=wx.TreeItemIcon_Normal ) if HwndHasChildren(hwnd, self.includeInvisible): self.SetItemHasChildren(index, True)
def __init__(self, parent, hwnds): wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT | wx.LC_SINGLE_SEL) listmix.ListCtrlAutoWidthMixin.__init__(self) imageList = wx.ImageList(16, 16) imageList.Add(GetInternalBitmap("cwindow")) self.AssignImageList(imageList, wx.IMAGE_LIST_SMALL) self.InsertColumn(0, "Program") self.InsertColumn(1, "Name") self.InsertColumn(2, "Class") self.InsertColumn(3, "Handle", wx.LIST_FORMAT_RIGHT) for hwnd in hwnds: imageIdx = 0 icon = GetHwndIcon(hwnd) if icon: imageIdx = imageList.AddIcon(icon) idx = self.InsertImageStringItem(sys.maxint, GetWindowProcessName(hwnd), imageIdx) self.SetStringItem(idx, 1, GetWindowText(hwnd)) self.SetStringItem(idx, 2, GetClassName(hwnd)) self.SetStringItem(idx, 3, str(hwnd)) for i in range(4): self.SetColumnWidth(i, -2) headerSize = self.GetColumnWidth(i) self.SetColumnWidth(i, -1) labelSize = self.GetColumnWidth(i) if headerSize > labelSize: self.SetColumnWidth(i, headerSize)
def __init__(self, hwnd): self.hwnd = hwnd self.pid = GetWindowPid(hwnd) self.name = splitext(GetProcessName(self.pid))[0] # The following may change during a window's lifetime self.title = GetWindowText(hwnd) self.window_class = GetClassName(hwnd)
def __call__(self, item=0): hwnd = eg.lastFoundWindows[0] clsName = GetClassName(hwnd) if clsName == 'TStatusBar' or clsName == 'msctls_statusbar32': result = GetStatusBarText(hwnd, 1024) if item: result = result[item - 1] elif len(result) == 1: result = result[0] else: result = GetWindowText(hwnd) return result
def __init__(self, hwnd): if not hwnd: raise ValueError("Invalid hwnd") self.hwnd = hwnd dwProcessId = DWORD() GetWindowThreadProcessId(hwnd, byref(dwProcessId)) self.pid = dwProcessId.value self.name = splitext(GetProcessName(self.pid))[0] # The following may change during a window's lifetime self.cached_title = ourName if self.pid == GetProcessId( ) else GetWindowText(hwnd) self.cached_class = GetClassName(hwnd)
def __start__(self, *dummyArgs): self.names, self.hwnds = EnumProcesses() self.flashing = set() self.lastActivated = None eg.messageReceiver.AddHandler(WM_APP + 1, self.WindowGotFocusProc) eg.messageReceiver.AddHandler(WM_APP + 2, self.WindowCreatedProc) eg.messageReceiver.AddHandler(WM_APP + 3, self.WindowDestroyedProc) eg.messageReceiver.AddHandler(WM_SHELLHOOKMESSAGE, self.MyWndProc) RegisterShellHookWindow(eg.messageReceiver.hwnd) self.hookDll = CDLL(abspath(join(dirname(__file__), "TaskHook.dll"))) self.hookDll.StartHook() trayWindow = 0 if "explorer" in self.names: for hwnd in self.names["explorer"].hwnds: if GetClassName(hwnd) == "Shell_TrayWnd": trayWindow = hwnd break self.desktopHwnds = (GetShellWindow(), trayWindow)
def __getattribute__(self, name): if name == 'is_visible': return win32gui.IsWindowVisible(self.hwnd) elif name == 'is_enabled': return win32gui.IsWindowEnabled(self.hwnd) elif name == 'title': # If the window is closed, GetWindowText and GetClassName # return empty strings, so return the cached versions. title = GetWindowText(self.hwnd) if title != '': self.title = title # Intentionally fall through to end of method elif name == 'window_class': win_class = GetClassName(self.hwnd) if win_class != '': self.window_class = win_class # Intentionally fall through to end of method return object.__getattribute__(self, name)
def AppendToplevelWindows(self, pid, item): hwnds = self.pids[pid] for hwnd in hwnds: try: name = GetWindowText(hwnd) className = GetClassName(hwnd) icon = GetHwndIcon(hwnd) except: continue if name != '': name = '"%s"' % name iconIndex = 0 if icon: iconIndex = self.imageList.AddIcon(icon) newItem = self.AppendItem(item, name) self.SetPyData(newItem, hwnd) self.SetItemText(newItem, name + className) self.SetItemImage(newItem, iconIndex, which=wx.TreeItemIcon_Normal) if HwndHasChildren(hwnd, self.includeInvisible): self.SetItemHasChildren(newItem, True)
def __start__(self, *dummyArgs): self.pids, self.hwnds = EnumProcesses() self.flashing = set() self.lastActivated = None eg.messageReceiver.AddHandler(WM_APP + 1, self.WindowGotFocusProc) eg.messageReceiver.AddHandler(WM_APP + 2, self.WindowCreatedProc) eg.messageReceiver.AddHandler(WM_APP + 3, self.WindowDestroyedProc) eg.messageReceiver.AddHandler(WM_SHELLHOOKMESSAGE, self.MyWndProc) RegisterShellHookWindow(eg.messageReceiver.hwnd) trayWindow = 0 for explorerPid in [ x for x in self.pids if self.pids[x].name == "explorer" ]: for hwnd in self.pids[explorerPid].hwnds: if GetClassName(hwnd) == "Shell_TrayWnd": trayWindow = hwnd break if trayWindow != 0: break self.desktopHwnds = (GetShellWindow(), trayWindow)
def OnSelectionChanged(self, event): event.Skip() tree = self.tree item = tree.GetSelection() if not item.IsOk(): return hwnd = tree.GetPyData(item) eg.PrintDebugNotice("HWND:", hwnd) if tree.GetItemParent(item) == tree.root: # only selected a program pid = hwnd hwnd = None else: pid = GetWindowThreadProcessId(hwnd)[1] if pid == self.lastPid and hwnd == self.lastHwnd: return self.lastPid = pid self.lastHwnd = hwnd exe = GetProcessName(pid) def SetOption(flag, option, value): checkBox, textCtrl = option checkBox.SetValue(flag) textCtrl.SetValue(value) textCtrl.Enable(flag) rootHwnd = None options = self.options SetOption(bool(exe), options[0], exe) if hwnd is not None: rootHwnd = GetAncestor(hwnd, GA_ROOT) targetWinName = GetWindowText(rootHwnd) targetWinClass = GetClassName(rootHwnd) SetOption(True, options[1], targetWinName) SetOption(True, options[2], targetWinClass) else: SetOption(False, options[1], "") SetOption(False, options[2], "") if rootHwnd is not None and rootHwnd != hwnd: targetWinName = GetWindowText(hwnd) targetWinClass = GetClassName(hwnd) SetOption(True, options[3], targetWinName) SetOption(True, options[4], targetWinClass) searchHwnd = hwnd data = [ child for child in GetWindowChildsList( rootHwnd, tree.includeInvisible ) if ( GetClassName(child) == targetWinClass and GetWindowText(child) == targetWinName ) ] try: count = data.index(searchHwnd) + 1 except: count = 0 else: SetOption(False, options[3], "") SetOption(False, options[4], "") if rootHwnd is not None: data = [ hwnd for hwnd in GetTopLevelWindowList(tree.includeInvisible) # NOQA if ( GetClassName(hwnd) == targetWinClass and GetWindowText(hwnd) != targetWinName and GetWindowThreadProcessId(hwnd)[1] == pid ) ] count = len(data) else: count = 0 SetOption(count > 0, options[5], count or 1)
def window_class(self): if self.IsAlive(): self.cached_class = GetClassName(self.hwnd) return self.cached_class