[Tutor] making aaa.txt in notepad focused.

Bill Burns billburns at pennswoods.net
Thu Jul 12 04:12:41 CEST 2007


elis aeris wrote:
> import time
> from ctypes import *
> 
> # Load up the Win32 APIs we need to use.
> GetForegroundWindow = windll.user32.GetForegroundWindow
> 
> 
> foreground_window = GetForegroundWindow()
> 
> 
> 
> 
> 
> this is a part of a code I from a separate project.
> 
> 
> I am trying to find out it's possible to do this:
> 
> handle = gesomethingfromthefocusedwindow()
> 
> later when I want to do this:
> 
> handle.gainfocus()
> 
> 
> and zap that window to the front!
> 

So you have a text file open with Notepad? And the file is 'aaa.txt' and
you want Notepad to be active (have the focus)?

If so, try this:

<code>
from ctypes import windll

user32 = windll.user32

SW_RESTORE = 9

hwnd = user32.FindWindowA(None, 'aaa.txt - Notepad')
if hwnd:
     user32.ShowWindow(hwnd, SW_RESTORE)
     user32.SetForegroundWindow(hwnd)
</code>

Bill




More information about the Tutor mailing list