> BTW, most of this has been said before a few times. Browse 
> the archives for 
> more info.

Yep! I was just about to re-post this (because we know by now that the
archive search does not really find all you're looking for):

==================================================
> Sent: Wednesday, March 28, 2001 15:17
> To: 'perl-win32-gui-users@lists.sourceforge.net'
> Subject: RE: [perl-win32-gui-users] Looping Question

[...]

The basic knack is
Win32::GUI::DoEvents() while Win32::GUI::PeekMessage(0,0,0);

You can call this even from inside an event. Here's a complete example,
taking care of avoiding restarting the busy loop before it completed, and of
aborting the busy loop when the program terminates.

have fun,
Harald

use Win32::GUI;

$Main = new Win32::GUI::Window (-name => 'Main',
        -pos => [100, 100], -size => [400, 300]);
sub Main_Terminate {-1}

$Main->AddButton (-name => $_ = 'Click',
        -text => $_, -pos => [160, 80]);
sub Click_Click {$Main->MessageBox ("Don't do that")}

$Main->AddButton (-name => $_ = 'Busy',
        -text => $_, -pos => [160, 120]);
sub Busy_Click
{
        return 0 if $busy++;
        for ($i = 0; $i < 1e5; $i++)
        {
                print "$i\r";
                while (Win32::GUI::PeekMessage(0,0,0))
                {
                        return -1 if Win32::GUI::DoEvents() < 0;
                }
        }
        $busy = 0;
}

$Main->Show ();
Win32::GUI::Dialog ();

Reply via email to