[Tutor] Controlling MS Windows programs?

Alan Gauld alan.gauld at btinternet.com
Thu Oct 4 09:27:20 CEST 2007


"Fast Primes" <fast_primes at hotmail.com> wrote 

> I am looking for ways to control multiple Windows programs 
> from Python, such that I can enter data via Python and have 
> that data passed to an underlying third party program's GUI 
> screen, ...
> Is it possible to come at this in a more straight forward way 
> than having to concern oneself with COM and the related 
> Windows internals?

COM *is* the straightforward way, that is what COM is for.
If you can't use COM you have to go through the far less 
reliable route of "screen scraping" the GUI. This involves 
passing windows messages to the target application to 
simulate user events. Look at the PostMessage function 
in the Win32 API (Check it on MSDN) as an example.

Getting data back out can be even more tricky unless 
you can get the "handle" of the widgets concerned.
That can usually be done with a combination of 
FindWindow() and GetChildWindows() calls

You can access the API functions via ctypes. 
But COM is actually easier in most cases

Windows was not designed for scripting! Thats 
why DDE/OLE/COM was developed.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list