Foggy Bottoms has asked for the wisdom of the Perl Monks concerning the following question:

Under MS Windows, how can I know which is the active window (the one that currently has the focus) ? Thanks

Replies are listed 'Best First'.
Re: find active window
by Corion (Patriarch) on Jun 10, 2003 at 13:04 UTC

    I think that Win32::GUI is the right way, and GetForegroundWindow() gives you the window handle of the window currently having the focus :

    perl -MWin32::GUI -wle "print Win32::GUI::GetForegroundWindow()"
Re: find active window
by PodMaster (Abbot) on Jun 10, 2003 at 11:30 UTC
    Use one of the Win32:: modules, like Win32::API, and then make the appropriate API call (I just happen to know it's GetForegroundWindow cause I use AMMO SDK)

    update: I just remembered Win32::GuiTest ( * ) .


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      Thanks a bunch... It sends me an ID # now. I'm all settled then. Thanks again.
Re: find active window
by nite_man (Deacon) on Jun 10, 2003 at 11:59 UTC
      it returns 0 however... :(

      Here's my bit of code :

      sub activeWindow
      # this method returns the handler of the active window
      {
      return Win32::GUI::GetActiveWindow();
      }

      And here's what I get when I print it:
      0

      What's wrong with that ? (I'm sorry but I've just begun Perl and I'm not familiar with it yet).
Re: find active window
by arthas (Hermit) on Jun 10, 2003 at 11:18 UTC

    Are you using a particular GUI toolkit? If so, which?

    Michele.