Last active
June 16, 2024 11:13
-
-
Save inaz2/6f72f18af15c47ab7432 to your computer and use it in GitHub Desktop.
EnumWindows + GetWindowText by Python ctypes (Cygwin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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