[python-win32] Creating a process and getting a handle

Mike Driscoll mdriscoll at co.marshall.ia.us
Wed Jan 23 16:27:34 CET 2008


Alec,

> 
> Date: Tue, 22 Jan 2008 23:26:50 -0800 (PST)
> From: Alec Bennett <whatyoulookin at yahoo.com>
> Subject: Re: [python-win32] Creating a process and getting a handle
> To: Tim Roberts <timr at probo.com>, Python-Win32 List
> 	<python-win32 at python.org>
> Message-ID: <316017.40385.qm at web54603.mail.re2.yahoo.com>
> Content-Type: text/plain; charset=iso-8859-1
> 
> Please post what you find on this, I'm curious too.
> 
> If you do go the enum windows route, It thought I'd
> post my notes on this since I recently got it working.
> It's somewhat confusing (for me at least) since it
> uses a callback:
> 
> 
> # Callback function for findWindowHandle
> def windowEnumerationHandler(hwnd, resultList):
> 
>     resultList.append((hwnd,
> win32gui.GetWindowText(hwnd)))
> 
> 
> def findWindowHandle(string):
> 
>     topWindows = []
> 
>     win32gui.EnumWindows(windowEnumerationHandler,
> topWindows)
> 
>     for window in topWindows:
>         if string in window[1]: return window[0],
> window[1]
> 
>     # Looks like we didn't find anything
>     return None, None
> 
> 
> handle, windowtext = findWindowHandle("Notepad")

I actually use a method similar to this later on in my program. But as I
mentioned to Tim, I was trying to get a handle on a window that I open so
I wouldn't have to search for it. I use the search method already to find
the source code window that I open from within IE. Sometimes automation
sucks.

Mike Driscoll
Applications Specialist
MCIS - Technology Center



More information about the python-win32 mailing list