Using Pythonwin to poke at Windows apps?

Thomas Heller theller at
Thu Mar 11 16:08:37 CET 2004

Henrik.Weber at (Henrik Weber) writes:

> Now I've tried this with ctypes:
> from ctypes import *
> import win32ui, win32con
> e = win32ui.FindWindow("ExploreWClass", None)
> w = win32ui.FindWindowEx(e, None, "WorkerW", None)
> w = win32ui.FindWindowEx(w, None, "ReBarWindow32", None)
> t = win32ui.FindWindowEx(w, None, "ToolbarWindow32", None)
> t = win32ui.FindWindowEx(w, t, "ToolbarWindow32", None)
> class TBBUTTON(Structure):
>     _fields_ = (("iBitmap", c_int),
>                 ("idCommand", c_int),
>                 ("fsState", c_byte),
>                 ("fsStyle", c_byte),
>                 ("bReserved", c_byte * 2),
>                 ("dwData", POINTER(c_long)),
>                 ("iString", c_char_p))
> b = TBBUTTON()
> f = windll.user32.SendMessageA
> TB_GETBUTTON = win32con.WM_USER + 23
> print f(t.GetSafeHwnd(), TB_GETBUTTON, 0, byref(b))
> When I run it the first time I get a return value 1. However the
> TBBUTTON structure contains mostly zeroes. Running it again crashes
> the Explorer. Even if I open another Explorer the script will crash it
> with every subsequent execution until the machine is rebooted.

I had to change the first FindWindow call to this:
  e = win32ui.FindWindow("CabinetWClass", None)
and then it finds an instance of the normal Windows Explorer, on XP pro.

You are correct that the TBBUTTON instance contains all zeros, but it
doesn't crash for me.  Of course I'm not running a released version of
ctypes, instead a patched cvs version.

I cannot see anything that is wrong, it seems that the SendMessage call
doesn't change anything in the TBBUTTON instance.  Can it be that some
messages are not valid over process boundaries?


More information about the Python-list mailing list