免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2216 | 回复: 3
打印 上一主题 下一主题

[继续求助,有进展]win32::GUI问三 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-21 13:54 |只看该作者 |倒序浏览
问二的继续:http://bbs.chinaunix.net/thread-1270279-1-1.html

按stop可以暂停了,但是图形界面显然通道阻塞了(不可控)使用了多线程也无用。继续请教各位高手!

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 {
        my $thr = new threads(\&mythread );
        $thr->detach();
}



sub mythread {
$pg = 9;
while($pg > 1){
$Text_Informa->Append( "$pg\n";
sleep 1;
if($control==1){last;}
$pg--;
}}

sub EndIt {my  $con=shift; <>; $$con=1; return;  }   
#参考自[http://topic.csdn.net/t/20050503/16/3981999.html#[/url]
sub btnStop_Click { my $thr1 = new threads(\&mythread1); $thr1->join(); }
sub mythread1 {my $thd=new threads("EndIt",\$control); $thd->join(); }

[ 本帖最后由 3chi01 于 2008-9-21 13:59 编辑 ]

SpxImage.jpg (14.66 KB, 下载次数: 30)

SpxImage.jpg

论坛徽章:
0
2 [报告]
发表于 2008-09-22 09:25 |只看该作者
如果tk是有办法的。win32::GUI不会了,顶一下。求助各位。

论坛徽章:
0
3 [报告]
发表于 2008-09-24 13:59 |只看该作者
你这个代码btnStop_Click函数阻塞住了
threads 之间不能共享内存的啊,要用threads::shared

论坛徽章:
0
4 [报告]
发表于 2008-09-24 23:38 |只看该作者
多谢feilong_36指点迷津,我还需要十分学习!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP