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 CheckWindow(self, hwnd): hwnd2 = GetAncestor(hwnd, GA_ROOT) if hwnd == 0 or hwnd2 in self.desktopHwnds: return "Desktop", 0 if hwnd != hwnd2: return if GetWindowLong(hwnd, GWL_HWNDPARENT): return if not IsWindowVisible(hwnd): return if hwnd in self.hwnds: return self.hwnds[hwnd].name, hwnd pid = GetWindowPid(hwnd) name = splitext(GetProcessName(pid))[0] processInfo = self.names.get(name, None) if not processInfo: processInfo = ProcessInfo(name) self.names[name] = processInfo self.TriggerEvent("Created." + name) processInfo.hwnds.add(hwnd) self.hwnds[hwnd] = processInfo self.TriggerEvent("NewWindow." + name) return name, hwnd
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 EnumProcesses(): names = {} hwnds = {} dwProcessId = DWORD() for hwnd in GetTopLevelWindowList(False): GetWindowThreadProcessId(hwnd, byref(dwProcessId)) pid = dwProcessId.value name = splitext(GetProcessName(pid))[0] if name not in names: processInfo = ProcessInfo(name) names[name] = processInfo else: processInfo = names[name] processInfo.hwnds.add(hwnd) hwnds[hwnd] = processInfo return names, hwnds
def __init__(self, pid): self.pid = pid self.name = splitext(GetProcessName(pid))[0] self.hwnds = dict() # key=hwnd, val=WindowInfo(hwnd)