[python-win32] Creating a process and getting a handle
Mike Driscoll
mdriscoll at co.marshall.ia.us
Tue Jan 22 23:40:03 CET 2008
Hi,
I am trying to get a handle on an external process (Internet Explorer 6 in
this case) that I open using win32process. I need the handle so that I can
make said process the top window. Here's what I've tried so far:
<code>
import win32process
import win32gui
info = win32process.CreateProcess(None, proc, None, None, 0,
win32process.NORMAL_PRIORITY_CLASS, None, None,
win32process.STARTUPINFO())
handle = info[0]
# attempt to make Internet Explorer 6 the Foreground Window
win32gui.SetForegroundWindow(handle)
</code>
Unfortunately, this results in a traceback:
Traceback (most recent call last):
File "<pyshell#12>", line 1, in ?
win32gui.SetForegroundWindow(info[2])
error: (1400, 'SetForegroundWindow', 'Invalid window handle.')
I can get the handle by doing this:
hwnd = win32gui.FindWindow('IEFrame',None)
But if there's multiple Explorer windows open, I may not get the window I
want. That's why I would like to create my own so I can have what amounts
to an "exclusive" handle to it. Any hints would be appreciated.
I am using Windows XP SP2 with Python 2.4.3. Thanks!
Mike Driscoll
Applications Specialist
MCIS - Technology Center
More information about the python-win32
mailing list