[python-win32] Suitability of PyWin32 to manipulate windows

Tim Roberts timr at probo.com
Tue Jan 15 20:02:53 CET 2008


Torbjørn Kristoffersen wrote:
> Hello, I'm not very familiar with Windows programming, so I would very much
> like some advice here.
>
> My goal is to start two programs from Python in Windows. These two windows
> will be maximized and cover the entire screen.
>
> Is Pywin32 capable of keeping track of these two programs, and control them in
> such a way that they can be focused (i.e. become the window on top, covering the
> other window) from my Python program?
>   

Yes, based on your description.  There are packages that make Windows 
automation a bit easier, but what you're describing doesn't even need 
that.  You can use win32ui.FindWindow to get window handles for the 
windows, based on their titles and/or window classes.  Once you have 
that, you can use SetWindowPos to adjust the "z-order" of the windows, 
which is the term Windows uses to describe the stacking order.  This 
forces a Notepad window to the rear:

    import win32con, win32ui
    p = win32ui.FindWindow( None, "x.txt - Notepad" )
    p.SetWindowPos( win32con.HWND_BOTTOM, (0,0,0,0),
        win32con.SWP_NOMOVE+win32con.SWP_NOSIZE+win32con.SWP_NOREPOSITION
    )

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list