Win32-GuiTest

 view release on metacpan or  search on metacpan

lib/Win32/GuiTest/Examples.pm  view on Meta::CPAN

    
    
    # Test WaitWindow()
    
    # en i18n constants 
    sub SOL  { "^Solitaire" }
    sub GAME { "%G" }
    sub OPT  { "O" }
    sub OPTIONS { "^Options" }
    sub CANCEL  { "Cancel" }
    
    # es i18n constants 
    #sub SOL  { "^Solitario" }
    #sub GAME { "%J" }
    #sub OPT  { "O" }
    #sub OPTIONS { "^Opciones" }
    #sub CANCEL  { "Cancelar" }
    
    # Open program
    system("start sol.exe");
    # Wait for program window to appear.
    die "Couldn't open solitaire program!\n"
        unless WaitWindow(SOL);
    # Select game menu
    SendKeys(GAME);
    # Open options menu
    SendKeys(OPT); 
    # Wait for options menu to appear for up to 5 seconds.
    WaitWindow(OPTIONS, 5);
    # Close options menu
    PushButton(CANCEL);
    # Close program
    SendKeys("%{F4}"); 
    

=head2 eg/which.pl

    #!/usr/bin/perl
    # Similar to UNIX which command.
    #
    # On my NT box:
    # 
    #  D:\src\perl\win32-guitest>eg\which.pl perl
    #  D:\perl\bin\perl.EXE
    #  D:\src\perl\win32-guitest>eg\which.pl regedit
    #  C:\WINNT\regedit.EXE
    #  D:\src\perl\win32-guitest>eg\which.pl notepad
    #  C:\WINNT\system32\notepad.EXE
    #  D:\src\perl\win32-guitest>
    #
    
    use strict;
    use Win32::GuiTest::Cmd qw(WhichExe);
    print WhichExe(shift);

=head2 eg/winbmp.pl

    #!/usr/bin/perl
    # This script has been written by Jarek Jurasz jurasz@imb.uni-karlsruhe.de
    # Save a given window as BMP file
    # Copy the contents to the clipboard
    
    
    use Win32::GuiTest qw(:ALL);
    
    ($w) = FindWindowLike(0, "^Calc");
    $w = GetDesktopWindow unless $w;
    
    $ds = new Win32::GuiTest::DibSect;
    $ds->CopyWindow($w);
    #$ds->CopyClient(GetDesktopWindow(), \@{[GetWindowRect($w)]});
    # $ds->Invert();
    #$ds->CopyClient(GetDesktopWindow(), \@{[GetWindowRect($w)]});
    # $ds->Invert();
    #$ds->ToGrayScale();
    $ds->SaveAs("bla.bmp");
    $ds->ToClipboard();

=head2 eg/wptr.pl

    #!/usr/bin/perl
    #
    
    # Module Pragmas
    use strict;
    use warnings;
    
    # Module Imports
    use Win32::GuiTest qw(GetCursorPos GetClassName GetWindowText
    	GetWindowRect WindowFromPoint GetWindowID IsKeyPressed WMGetText);
    use Win32::Clipboard;
    
    # Module Level Variables
    my $Clip = Win32::Clipboard();
    my $cur_info = "";
    my $oldhwnd = 0;
    my $oldcx = 0;
    my $oldcy = 0;
    
    # Core Loop
    while (1) {
    	my ($cx, $cy) = GetCursorPos();
    	# Is different cursor position?
    	if ( ($cx != $oldcx) || ($cy != $oldcy) ) {
    		$oldcx = $cx;
    		$oldcy = $cy;
    		# Get handle of window
    		my $hwnd = WindowFromPoint($cx, $cy);
    		if ($hwnd == $oldhwnd) {
    			# Same window as before, don't query information again.
    			next;
    		}
    		# Different window, so cache the handle value.
    		$oldhwnd = $hwnd;
    		# Get information for the new window in which the cursor is over.
    		$cur_info = GetWindowInfo($hwnd);
    		ClearScreen();
    		# Output window information to console.
    		DispWindowInfo($cur_info);
    		# Display menu.
    		DispMenu();
    	}
    	# INSERT to copy window data to clipboard.
    	if (IsKeyPressed("INS")) {
    		$Clip->Empty();
    		$Clip->Set($cur_info);
    		select(undef, undef, undef, 0.50);
    		print "Copied data to clipboard.\n";
    	}
    	# ESCAPE to exit this program.
    	if (IsKeyPressed("ESC")) {
    		print "Goodbye!\n";
    		last;
    	}
    }
    
    
    sub ClearScreen {
    	system("command /c cls");
    	return;
    }
    
    sub GetWindowInfo {
    	my $hwnd = shift;
    	my $info = 		"# Window Text: '" . GetWindowText($hwnd) . "'\r\n";
    	$info = $info . "# Window Class: '" . GetClassName($hwnd) . "'\r\n";
    	$info = $info . "# Window ID: " . GetWindowID($hwnd) . "\r\n";
    	my ($left, $top, $right, $bottom) = GetWindowRect($hwnd);
    	$info = $info . "# Window Rect: ($left, $top) - ($right, $bottom)\r\n";
    print "Text: " . WMGetText($hwnd) . "\r\n";
    	return($info);
    }
    
    sub DispWindowInfo {
    	print shift;
    	return;
    }
    
    sub DispMenu {
    	print "\n\nPress <INSERT> to copy window text to clipboard.\n";
    	print "Press <ESCAPE> to exit program.\n";
    	return;
    }



=cut



( run in 2.792 seconds using v1.01-cache-2.11-cpan-81fc1098f69 )