From: Gossett, M. <mal...@ve...> - 2002-08-26 17:32:41
|
Johan, that is a pretty good explanation. I'm a bit new to Win32::GUI, having used TK more, but never became a super user with it either. Once question I have, I notice that subroutines don't need specific calls, so how do they get called. A perfect example would be the hello.pl from th 665 source release. How are the subroutines being called in this? Thanks Mal use Win32::GUI; $MW =3D new Win32::GUI::Window( -title =3D> 'hello.pl', -left =3D> 100, -top =3D> 100, -width =3D> 150, -height =3D> 100, -name =3D> 'MainWindow', -visible =3D> 1, ); #Add controls my $label =3D $MW->AddLabel(-text =3D> "This is my text.",=20 -font =3D> $font); $hello =3D $MW->AddButton( -text =3D> 'Hello, world', -name =3D> 'Hello', -left =3D> 25, -top =3D> 25, ); $MW->Show(); $rc =3D Win32::GUI::Dialog(0); sub MainWindow_Terminate { $MW->PostQuitMessage(1); # return -1; } sub Hello_Click { if($MW->Hello->Text eq "Hello, world") { $MW->Hello->{-text} =3D "OneMoreTime"; } else { print STDOUT "Hello, world\n"; $MW->PostQuitMessage(0); } } -----Original Message----- From: Johan Lindstrom [mailto:jo...@ba...]=20 Sent: Monday, August 26, 2002 10:21 AM To: per...@li... Subject: Re: [perl-win32-gui-users] first app ? At 08:03 2000-08-27 +0300, ra...@un... wrote: >I've just installed win32::gui but how i will do my first app if I try=20 >this : > >use Win32::GUI; >my $w =3D new Win32::GUI(-name =3D> 'XX'); >$w->Show(); > >But the window just got created and destroyed imedietly !?! Why this=20 >happen ? Unlike your vanilla Perl program, most event based programs run what's=20 called a main event loop. A GUI is most often event based. It means that you start it, and then it sits there waiting for user input (events, like=20 mouse clicks on buttons, or timers being triggered). In Win32::GUI, you enter the main loop by calling Win32::GUI::Dialog(), so=20 you should add that to your program, after the Show(). Before entering the main loop you should have created all your windows (and=20 Show():ed the ones you want visible from the beginning). In most cases you=20 should never call Win32::GUI::Dialog() more than once in your program. After you call Win32::GUI::Dialog(), the only way to exit is from an event.=20 This happens when an event handler returns -1. Typically, the Terminate=20 event handler of your application window should return -1. In your case: sub XX_Terminate { return(-1); } In other cases, you want to Hide() the window (and return 0) in the=20 Terminate event handler instead, so you can Show() it again at a later time. /J -------- ------ ---- --- -- -- -- - - - - - Johan Lindstr=F6m Sourcerer @ Boss Casinos jo...@ba... Latest bookmark: "Salon.com Technology I come to bury IAmCarbona..." <http://www.salon.com/tech/feature/2002/08/03/deleteddomains/index.html> dmoz (1 of 13): /Computers/Internet/On_the_Web/Weblogs/Tools ------------------------------------------------------- This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE! https://www.inphonic.com/r.asp?r=3Dsourceforge1&refcode1=3Dvs3390 _______________________________________________ Perl-Win32-GUI-Users mailing list Per...@li... https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users |