I'm trying to get a list of all visible windows using ctypes in Python3.3
But with the code i have, not a single window is returned. The EnumWindows
function fails, and the returned error code is 0.
import ctypes
user32 = ctypes.windll.user32
def worker(hwnd, lParam):
length = user32.GetWindowTextLengthW(hwnd) + 1
buffer = ctypes.create_unicode_buffer(length)
user32.GetWindowTextW(hwnd, buffer, length)
print("Buff: ", repr(buffer.value))
a = ctypes.WINFUNCTYPE(ctypes.c_bool,
ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_int))(worker)
if not user32.EnumWindows(a, True):
print("Err: ", ctypes.windll.kernel32.GetLastError())
Here is the current output:
Buff: ''
Err: 0
And this is what i expected:
Buff: 'Python 3.3.2 shell'
Buff: 'test.py - C:\Users\...'
[...]
Could you point me in the right direction to achieve this? Thanks in advance.