Mark Mc Mahon sent me personal email with the answer that I ought to
be using SetForegroundWindow. For this I needed a window handle, and
for that I think I needed a window name. Since I can't be sure of the
full window name (it changes based on the active document), I wrote
the following function that uses a regexp to match the names of all
active windows:

#------------------------------------------------------------
def RaiseWindowNamed(nameRe):
  import win32gui
  # start by getting a list of all the windows:
  cb = lambda x,y: y.append(x)
  wins = []
  win32gui.EnumWindows(cb,wins)

  # now check to see if any match our regexp:
  tgtWin = -1
  for win in wins:
    txt = win32gui.GetWindowText(win)
    if nameRe.match(txt):
      tgtWin=win
      break

  if tgtWin>=0:
    win32gui.SetForegroundWindow(tgtWin)
#------------------------------------------------------------

This seems to do what I want it to do.

Thanks Mark!

-greg
_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to