in reply to Win32 Active Window

This works for me -

use Win32::GuiTest qw/ FindWindowLike SetForegroundWindow GetDesktopWindow IsWindowVisible /; my @handles = grep {IsWindowVisible($_) } FindWindowLike(GetDesktopWindow(), qr/^Microsoft Excel/, undef, undef); die "Too many windows\n" if (@handles > 1); die "Not enough windows\n" if (@handles < 1); my $excel = shift @handles; SetForegroundWindow($excel);

 

Replies are listed 'Best First'.
Re^2: Win32 Active Window
by Grygonos (Chaplain) on Dec 07, 2004 at 13:44 UTC

    If the only window you are competing with is the Word Window the following is tested and works on 5.8.0 on XP-SP2 with Office 97. You could probably just not make the word window visible also .. however if they both need to be in the taskbar.. this works fine.

    use strict; use warnings; use Win32::OLE; use Win32::OLE::Const; my $xl = Win32::OLE->new('Excel.Application'); my $xlConst = Win32::OLE::Const->Load('Microsoft Excel 8.0 Object Libr +ary'); #Add a workbook so the window doesn't autoclose $xl->Workbooks->Add(); my $word = Win32::OLE->new('Word.Application'); my $wordConst = Win32::OLE::Const->Load('Microsoft Word 8.0'); #Set both visible to test $word->{Visible} = -1; $xl->{Visible} = -1; #Minimize Word $word->{WindowState} = $wordConst->{'wdWindowStateMinimize'}; #Maximize Excel $xl->{WindowState} = $xlConst->{'xlMaximized'};