Skip to content

Instantly share code, notes, and snippets.

@geekman
Created May 24, 2012 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geekman/2779738 to your computer and use it in GitHub Desktop.
Save geekman/2779738 to your computer and use it in GitHub Desktop.
list normal open windows (like Alt-Tab or Task Manager does)
import win32con
import win32gui
import ctypes
_user32 = ctypes.windll.user32
excludes = (_user32.GetShellWindow(), win32gui.FindWindow('Shell_TrayWnd', None))
winlist = []
win32gui.EnumWindows(lambda hwnd, l: l.append(hwnd) if \
win32gui.IsWindowVisible(hwnd) and \
not win32gui.GetWindow(hwnd, win32con.GW_OWNER) and \
hwnd not in excludes \
else True, winlist)
# show results
print len(winlist)
for x in [(h, win32gui.GetClassName(h), win32gui.GetWindowText(h)) for h in winlist]:
print repr(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment