Accessing Win32 class names

Thomas Heller theller at python.net
Fri Jan 31 09:37:27 CET 2003


Tom Harris <TomH at 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




More information about the Python-list mailing list