Win32::GUI代码,测试通不过呀。 点击stop并没有停下来呀。


如何点击stop马上停止?各位前辈帮忙看看,谢谢了

QUOTE:
use Win32::GUI qw();
use threads;

#create main window
my $main = Win32::GUI::Window->new(
    -name   => 'Main',
    -width  => 410,
    -height => 220,
    -text   => 'test',
         -maxsize => [410, 220],
  -minsize => [410, 220],
);

$Text_Informa=$main->AddTextfield(
    -name => "Text_Informa",
    -left => 10,
    -top  => 80,
    -width => 383,
    -height => 100,
    -multiline => 1,
);


$main->AddButton(-name => 'btnDown', -text => 'Download',-left => 265, -top => 45,);
$btnStop=$main->AddButton(-name => 'btnStop', -text => 'Stop',-left => 338, -top => 45,);


# initialization
my $w = $main->ScaleWidth();
my $h = $main->ScaleHeight();
my $desk = Win32::GUI::GetDesktopWindow();
my $dw = Win32::GUI::Width($desk);
my $dh = Win32::GUI::Height($desk);
my $x = ($dw - $w) / 2;
my $y = ($dh - $h) / 2;
$main->Move($x, $y);
$main->Show();

Win32::GUI:ialog();  
exit(0);

# window event handler
sub Main_Terminate {
    -1; #terminate the message loop
}

sub Main_Resize {
    $main->Resize($main->ScaleWidth - 20, $main->ScaleHeight - 40);
}   


sub btnDown_Click {
           $flag = true;

        my $thr = new threads(\&mythread );
        $thr->detach();
}


sub mythread {
while($flag){
foreach($pg=1;$pg<=6;$pg++){$Text_Informa->Append( "$pg\n"; sleep 1;}
}
}

sub btnStop_Click {
$flag = false;
}