Update of /cvsroot/perl-win32-gui/Win32-GUI/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30555/samples
Added Files: Tutorial_Part1_hello1.pl Tutorial_Part1_hello2.pl Tutorial_Part1_hello3.pl Tutorial_Part1_hello4.pl Tutorial_Part1_hello5.pl Tutorial_Part1_hello6.pl Tutorial_Part2_framework.pl Tutorial_Part3_DialogBox.pl Tutorial_Part4_NotifyIcon.pl Tutorial_Part4_StatusBar.pl Tutorial_Part4_timer.pl Tutorial_Part5_modalWindow.pl Tutorial_Part5_popupWindow1.pl Tutorial_Part5_popupWindow2.pl Tutorial_Part5_twoWindows.pl Tutorial_Part9_noDosWindow.pl guiperl.ico Log Message: Bug fixes, update tutorial, add tutorial samples --- NEW FILE: Tutorial_Part4_timer.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $main = Win32::GUI::Window->new( -name => 'Main', -text => 'Perl', -width => 200, -height => 200 ); my $t1 = $main->AddTimer('T1', 1000); $main->Show(); Win32::GUI::Dialog(); exit(0); sub Main_Terminate { return -1; } sub T1_Timer { print "Timer went off!\n"; return 0; } --- NEW FILE: Tutorial_Part5_popupWindow1.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $W1 = Win32::GUI::Window->new( -name => "W1", -title => "First Window", -pos => [ 100, 100 ], -size => [ 300, 200 ], ); $W1->AddButton( -name => "Button1", -text => "Open popup window", -pos => [ 10, 10 ], ); my $W2 = Win32::GUI::Window->new( -name => "W2", -title => "Second Window", -pos => [ 150, 150 ], -size => [ 300, 200 ], ); $W2->AddButton( -name => "Button2", -text => "Close this window", -pos => [ 10, 10 ], ); $W1->Show(); Win32::GUI::Dialog(); exit(0); sub W1_Terminate { return -1; } sub Button1_Click { $W2->Show(); return 0; } sub Button2_Click { $W2->Hide(); return 0; } --- NEW FILE: Tutorial_Part3_DialogBox.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $main = Win32::GUI::DialogBox->new( -name => 'Main', -text => 'Perl', -width => 200, -height => 200 ); $main->AddButton( -name => 'Default', -text => 'Ok', -default => 1, # Give button darker border -ok => 1, # press 'Return' to click this button -width => 60, -height => 20, -left => $main->ScaleWidth() - 140, -top => $main->ScaleHeight() - 30, ); $main->AddButton( -name => 'Cancel', -text => 'Cancel', -cancel => 1, # press 'Esc' to click this button -width => 60, -height => 20, -left => $main->ScaleWidth() - 70, -top => $main->ScaleHeight() - 30, ); $main->Show(); Win32::GUI::Dialog(); exit(0); sub Main_Terminate { return -1; } sub Default_Click { print "Default button clicked\n"; return 0; } sub Cancel_Click { print "Cancel button clicked\n"; return 0; } --- NEW FILE: Tutorial_Part1_hello6.pl --- #!perl -w use strict; use warnings; use Win32::GUI; # Get text to diaply from the command line my $text = defined($ARGV[0]) ? $ARGV[0] : "Hello, world"; # Create our window my $main = Win32::GUI::Window->new( -name => 'Main', -width => 100, -height => 100, -text => 'Perl', ); # Create a font to diaply the text my $font = Win32::GUI::Font->new( -name => "Comic Sans MS", -size => 24, ); # Add the text to a label in the window my $label = $main->AddLabel( -text => $text, -font => $font, -foreground => 0x0000FF, ); my $ncw = $main->Width() - $main->ScaleWidth(); my $nch = $main->Height() - $main->ScaleHeight(); my $w = $label->Width() + $ncw; my $h = $label->Height() + $nch; # Get the desktop window and its size: my $desk = Win32::GUI::GetDesktopWindow(); my $dw = Win32::GUI::Width($desk); my $dh = Win32::GUI::Height($desk); # Calculate the top left corner position needed # for our main window to be centered on the screen my $x = ($dw - $w) / 2; my $y = ($dh - $h) / 2; # And move the main window to the center of the screen $main->Move($x, $y); # Resize the window to the size of the label $main->Resize($w, $h); # Set the minimum size of the window to the size of the label $main->Change( -minsize => [$w, $h], ); # SHow the window and enter the dialog phase. $main->Show(); Win32::GUI::Dialog(); exit(0); # Terminate Event handler sub Main_Terminate { return -1; } # Resize Event handler sub Main_Resize { my $mw = $main->ScaleWidth(); my $mh = $main->ScaleHeight(); my $lw = $label->Width(); my $lh = $label->Height(); $label->Left(($mw - $lw) / 2); $label->Top(($mh - $lh) / 2); return 0; } --- NEW FILE: Tutorial_Part4_NotifyIcon.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $main = Win32::GUI::Window->new( -name => 'Main', -text => 'Perl', -width => 200, -height => 200 ); my $icon = new Win32::GUI::Icon('GUIPERL.ICO'); my $ni = $main->AddNotifyIcon( -name => "NI", -id => 1, -icon => $icon, -tip => "Hello" ); Win32::GUI::Dialog(); exit(0); sub Main_Terminate { return -1; } sub Main_Minimize { $main->Disable(); $main->Hide(); return 1; } sub NI_Click { $main->Enable(); $main->Show(); return 1; } --- NEW FILE: guiperl.ico --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Tutorial_Part2_framework.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $main = Win32::GUI::Window->new( -name => 'Main', -text => 'Perl', -width => 200, -height => 200 ); $main->Show(); Win32::GUI::Dialog(); exit(0); sub Main_Terminate { return -1; } --- NEW FILE: Tutorial_Part1_hello5.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $text = defined($ARGV[0]) ? $ARGV[0] : "Hello, world"; my $main = Win32::GUI::Window->new( -name => 'Main', -width => 100, -height => 100, -text => 'Perl', ); my $font = Win32::GUI::Font->new( -name => "Comic Sans MS", -size => 24, ); my $label = $main->AddLabel( -text => $text, -font => $font, -foreground => 0x0000FF, ); my $ncw = $main->Width() - $main->ScaleWidth(); my $nch = $main->Height() - $main->ScaleHeight(); my $w = $label->Width() + $ncw; my $h = $label->Height() + $nch; $main->Resize($w, $h); # Get the desktop window and its size: my $desk = Win32::GUI::GetDesktopWindow(); my $dw = Win32::GUI::Width($desk); my $dh = Win32::GUI::Height($desk); # Calculate the top left corner position needed # for our main window to be centered on the screen my $x = ($dw - $w) / 2; my $y = ($dh - $h) / 2; # And move the main window to the center of the screen $main->Move($x, $y); $main->Show(); Win32::GUI::Dialog(); exit(0); sub Main_Terminate { return -1; } sub Main_Resize { my $mw = $main->ScaleWidth(); my $mh = $main->ScaleHeight(); my $lw = $label->Width(); my $lh = $label->Height(); if ($lw > $mw) { $main->Width($lw + $ncw); # Remember the non-client width! } else { $label->Left(($mw - $lw) / 2); } if ($lh > $mh) { $main->Height($lh + $nch); # Remember the non-client height! } else { $label->Top(($mh - $lh) / 2); } return 0; } --- NEW FILE: Tutorial_Part4_StatusBar.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $main = Win32::GUI::Window->new( -name => 'Main', -text => 'Perl', -width => 200, -height => 200 ); my $sb = $main->AddStatusBar(); $main->Show(); Win32::GUI::Dialog(); exit(0); sub Main_Terminate { return -1; } sub Main_Resize { $sb->Move( 0, ($main->ScaleHeight() - $sb->Height()) ); $sb->Resize( $main->ScaleWidth(), $sb->Height() ); $sb->Text( "Window size: " . $main->Width() . "x" . $main->Height() ); return 0; } --- NEW FILE: Tutorial_Part5_modalWindow.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $W1 = Win32::GUI::Window->new( -name => "W1", -title => "First Window", -pos => [ 100, 100 ], -size => [ 300, 200 ], ); $W1->AddButton( -name => "Button1", -text => "Open popup window", -pos => [ 10, 10 ], ); my $W2 = Win32::GUI::Window->new( -name => "W2", -title => "Second Window", -pos => [ 150, 150 ], -size => [ 300, 200 ], -parent => $W1, ); $W2->AddButton( -name => "Button2", -text => "Close this window", -pos => [ 10, 10 ], ); $W1->Show(); Win32::GUI::Dialog(); exit(0); sub W1_Terminate { return -1; } sub Button1_Click { $W2->DoModal(); return 0; } sub W2_Terminate { return -1; } sub Button2_Click { return -1; } --- NEW FILE: Tutorial_Part1_hello4.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $text = defined($ARGV[0]) ? $ARGV[0] : "Hello, world"; my $main = Win32::GUI::Window->new( -name => 'Main', -width => 100, -height => 100, -text => 'Perl', ); my $font = Win32::GUI::Font->new( -name => "Comic Sans MS", -size => 24, ); my $label = $main->AddLabel( -text => $text, -font => $font, -foreground => 0x0000FF, ); my $w = $label->Width() + $main->Width() - $main->ScaleWidth(); my $h = $label->Height() + $main->Height() - $main->ScaleHeight(); $main->Resize($w, $h); # Get the desktop window and its size: my $desk = Win32::GUI::GetDesktopWindow(); my $dw = Win32::GUI::Width($desk); my $dh = Win32::GUI::Height($desk); # Calculate the top left corner position needed # for our main window to be centered on the screen my $x = ($dw - $w) / 2; my $y = ($dh - $h) / 2; # And move the main window to the center of the screen $main->Move($x, $y); $main->Show(); Win32::GUI::Dialog(); exit(0); sub Main_Terminate { return -1; } --- NEW FILE: Tutorial_Part1_hello3.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $text = defined($ARGV[0]) ? $ARGV[0] : "Hello, world"; my $main = Win32::GUI::Window->new( -name => 'Main', -width => 100, -height => 100, -text => 'Perl', ); # Create a new Win32::GUI::Font object with which # we'll draw the text my $font = Win32::GUI::Font->new( -name => "Comic Sans MS", -size => 24, ); my $label = $main->AddLabel( -text => $text, -font => $font, # use the font we created -foreground => 0x0000FF, # use red text ); $main->Resize( $label->Width() + $main->Width() - $main->ScaleWidth(), $label->Height() + $main->Height() - $main->ScaleHeight() ); $main->Show(); Win32::GUI::Dialog(); exit(0); sub Main_Terminate { return -1; } --- NEW FILE: Tutorial_Part5_popupWindow2.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $W1 = Win32::GUI::Window->new( -name => "W1", -title => "First Window", -pos => [ 100, 100 ], -size => [ 300, 200 ], ); $W1->AddButton( -name => "Button1", -text => "Open popup window", -pos => [ 10, 10 ], ); my $W2 = Win32::GUI::Window->new( -name => "W2", -title => "Second Window", -pos => [ 150, 150 ], -size => [ 300, 200 ], ); $W2->AddButton( -name => "Button2", -text => "Close this window", -pos => [ 10, 10 ], ); $W1->Show(); Win32::GUI::Dialog(); exit(0); sub W1_Terminate { return -1; } sub Button1_Click { $W2->Show(); return 0; } sub W2_Terminate { $W2->Hide(); return 0; } sub Button2_Click { $W2->Hide(); return 0; } --- NEW FILE: Tutorial_Part5_twoWindows.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $W1 = Win32::GUI::Window->new( -name => "W1", -title => "First Window", -pos => [ 100, 100 ], -size => [ 300, 200 ], ); my $W2 = Win32::GUI::Window->new( -name => "W2", -title => "Second Window", -pos => [ 150, 150 ], -size => [ 300, 200 ], ); $W1->Show(); $W2->Show(); Win32::GUI::Dialog(); exit(0); sub W1_Terminate { return -1; } sub W2_Terminate { return -1; } --- NEW FILE: Tutorial_Part1_hello1.pl --- #!perl -w use strict; use warnings; use Win32::GUI; # Create a window, saving it in variable $main my $main = Win32::GUI::Window->new( -name => 'Main', -width => 100, -height => 100, ); # Add a label to the window (by default a label # has size big enough for its text and is positioned # in the top left of its containing window) $main->AddLabel( -text => "Hello, world", ); # Show our main window $main->Show(); # Enter the windows message loop, often referred # to as the "dialog phase". Win32::GUI::Dialog(); # When the message loopreturns control to our # perl program, then the interaction with the # GUI is complete, so we exit. exit(0); ###################### ###################### # The Terminate event handler for a window # named 'Main'. Returning -1 causes the # windows message loop to exit and return # control to our perl program. sub Main_Terminate { return -1; } --- NEW FILE: Tutorial_Part1_hello2.pl --- #!perl -w use strict; use warnings; use Win32::GUI; # Get the text to put in the label from the command line, # using 'Hello, world' as a default if nothing is provided. my $text = defined($ARGV[0]) ? $ARGV[0] : "Hello, world"; my $main = Win32::GUI::Window->new( -name => 'Main', -width => 100, -height => 100, -text => 'Perl', # Add a title ); my $label = $main->AddLabel( -text => $text, ); # Calculate the non-client area of the main window: my $ncw = $main->Width() - $main->ScaleWidth(); my $nch = $main->Height() - $main->ScaleHeight(); # Calculate the required size of the main window to # exactly fit the label: my $w = $label->Width() + $ncw; my $h = $label->Height() + $nch; # Resize the main window to the calculated size: $main->Resize($w, $h); $main->Show(); Win32::GUI::Dialog(); exit(0); sub Main_Terminate { return -1; } --- NEW FILE: Tutorial_Part9_noDosWindow.pl --- #!perl -w use strict; use warnings; use Win32::GUI; my $DOS = Win32::GUI::GetPerlWindow(); Win32::GUI::Hide($DOS); my $main = Win32::GUI::Window->new( -name => 'Main', -text => 'Perl', -width => 200, -height => 200 ); $main->Show(); Win32::GUI::Dialog(); Win32::GUI::Show($DOS); exit(0); sub Main_Terminate { return -1; }