[pm-h] Get Window Name

Christopher Eades houstonpm at chromaxs.com
Fri Jul 8 23:04:52 PDT 2011


If you're doing this on Windows, any toolkit, then there's two API's 
that you can use to get the foreground window (this does not necessarily 
mean your program's window... it could be the Start Menu, screen saver, 
desktop, etc):

GetForegroundWindow
http://msdn.microsoft.com/en-us/library/ms633505(VS.85).aspx

GetWindowText
http://msdn.microsoft.com/en-us/library/ms633520(VS.85).aspx

You'll need to research what modules you'll need to bring in to get 
access to these functions but it looks like CPAN has Win32::GuiTest that 
looks promising. You should be able to use something like this. Again, 
note it returns whatever the foreground window is... this is not 
necessarily your window:

use Win32::GuiTest qw(GetForegroundWindow GetWindowText);

my $foreground_hwnd = GetForegroundWindow();
my $windowtext      = GetWindowText($foreground_hwnd);

Does the windowing module/API you're using export anything that would 
give this information?

Fraser Baker wrote:
> Hi Guys:
>  
> I need to get the name of the current window using PERL. I've looked 
> around but can't find anything that works.
>  
> Fraser
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Houston mailing list
> Houston at pm.org
> http://mail.pm.org/mailman/listinfo/houston
> Website: http://houston.pm.org/


More information about the Houston mailing list