Skip to content

Instantly share code, notes, and snippets.

@inaz2
Last active June 23, 2022 23:10
Show Gist options
  • Save inaz2/6f72f18af15c47ab7432 to your computer and use it in GitHub Desktop.
Save inaz2/6f72f18af15c47ab7432 to your computer and use it in GitHub Desktop.
EnumWindows + GetWindowText by Python ctypes (Cygwin)
from ctypes import *
EnumWindows = cdll.user32.EnumWindows
EnumWindowsProc = CFUNCTYPE(c_bool, POINTER(c_int), POINTER(c_int))
GetWindowText = cdll.user32.GetWindowTextW
GetWindowTextLength = cdll.user32.GetWindowTextLengthW
IsWindowVisible = cdll.user32.IsWindowVisible
def enum_func(hwnd, lParam):
if IsWindowVisible(hwnd):
length = GetWindowTextLength(hwnd)
buff = create_unicode_buffer(length + 1)
GetWindowText(hwnd, buff, length + 1)
if buff.value:
print buff.value
EnumWindows(EnumWindowsProc(enum_func), 0)
$ python
Python 2.7.5 (default, Oct 2 2013, 22:34:09)
[GCC 4.8.1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ python enumwindows.py
Google - Mozilla Firefox
test
Program Manager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment