Accessing Win32 class names

27 views
Skip to first unread message

Tom Harris

unread,
Jan 30, 2003, 7:58:04 PM1/30/03
to
Greetings

Anyone know how to get the Windows class name knowing the handle in Python?
For some reason win32gui does not appear to wrap the API call GetClassName()

TomH <tomh(AT)optiscan(DOT)com>


Thomas Heller

unread,
Jan 31, 2003, 3:37:27 AM1/31/03
to
Tom Harris <To...@optiscan.com> writes:

> Greetings
>
> Anyone know how to get the Windows class name knowing the handle in Python?
> For some reason win32gui does not appear to wrap the API call GetClassName()

It's simple with ctypes:

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import windll, c_string
>>> user32 = windll.user32
>>> hwnd = user32.GetDesktopWindow()
>>> buf = c_string("\000" * 32)
>>> user32.GetClassName(hwnd, buf, len(buf))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
....
ValueError: function 'GetClassName' not found
>>> user32.GetClassNameA(hwnd, buf, len(buf))
6
>>> print buf.value
#32769

See http://starship.python.net/crew/theller/ctypes.html

Thomas

Reply all
Reply to author
Forward
0 new messages