"Universal Gateway"

Paul Moore gustav at morpheus.demon.co.uk
Thu Nov 7 16:17:10 EST 2002


Thomas Heller <theller at python.net> writes:

> Ok, it seems I cannot escape, now that ctypes also was mentioned in
> the Daily Python-URL, so I will also announce it here, after some
> cleanup.

Having looked at this, I'm very impressed. calldll did the job, but I
was never completely happy with its interface. Your code is far nicer,
and makes things very clean.

I was interested in the support for callbacks, and as there wasn't a
sample script in the distribution, I had a go at writing one. Took me
no more than a few minutes (most of which was looking up prototypes in
MSDN!) and worked straight off. It was a very nice experience :-)

In case you're interested, here's the code (just lists the window
titles of all the windows in the system).

---- cut here ----

from ctypes import windll, CFunction, c_string
user32 = windll.user32

class EnumWindowsProc(CFunction):
    _types_ = "ii"
    _stdcall_ = 1

def DisplayWindow(hwnd, lparam):
    title = c_string('\000' * 256)
    user32.GetWindowTextA(hwnd, title, 255)
    print title.value

enumproc = EnumWindowsProc(DisplayWindow)

user32.EnumWindows(enumproc, 0)

------------------

Paul.

-- 
This signature intentionally left blank



More information about the Python-list mailing list