From: Roger E. <ro...@er...> - 2005-09-03 00:21:31
|
Hi Greg, since you're apparently running on windows, maybe this may be of help: import win32gui, win32ui def _MyCallback( hwnd, extra ): extra.append(hwnd) windows = [] win32gui.EnumWindows(_MyCallback, windows) j = 0 winDict = {} for i in windows: if win32gui.IsWindowVisible(i): winDict[j] = i j += 1 win32gui.SetForegroundWindow(winDict[1]) # found this out by inspection # the key of the window on top try: fgwindow = win32ui.GetForegroundWindow() print fgwindow.GetWindowText() except: print "No window found on the ForeGround?!" I'm not very happy with this algorithm, but given my little knowledge of MS Windows and the very few times the exception is raised, it suffices in my case. Regards, Roger |