#!/usr/local/bin/perl -w use strict; use Data::Dumper; use Win32::GUI; use lib ("../lib"); use Win32::GUI::Window::Object; for (1..3) { my $id = int(rand(100)); my $win = DemoWindow->winCreate($id); $win->Show(); } Win32::GUI::Dialog(); package DemoWindow; #Inherit from the new Window-as-object class use base qw(Win32::GUI::Window::Object); #A demo property to give it some identity use Class::MethodMaker get_set => [ "no" ]; #Class method to create/build a window of this class. It #could eventually be a window built by TGL. # #This could be in the new() method as well, calling the #SUPER::new() to create the object, then setting the no() #property. # sub winCreate { my $pkg = shift; my ($no) = @_; my $self = $pkg->new( -left => 100 + int(rand(400)), -top => 50 + int(rand(200)), -width => 300, -height => 100, -name => "winMain", -text => "Window $no", ); $self->no($no); #Set the demo property my $btnHelloWorld = $self->AddButton( -name => "btnHelloWorld", -text => "Hello world!", -left => 10, -top => 10, -height => 20, -width => 100, ); return($self); } #Event handlers are ordinary methods, with $self as #the first parameter as usual. This gives context to the #event, making it possible to have many instances of the #same window class. sub winMain_Terminate { my $self = shift; print "winMain_Terminate from DemoWindow with no (" . $self->no . ")\n"; return(-1); } sub btnHelloWorld_Click { my $self = shift; my $no = $self->no(); print "btnHelloWorld_Click in DemoWindow no == $no\n"; $self->Text("Window $no - " . int(rand(100)) ); return(1); } __END__