All,

I found the threads example posted in this group and began playing around.
I've modified the code to add a splash screen using
Win32::GUI:SplashScreen, a timer taken from Tutorial_Part4_timer.pl, a
statusbar, and a notifyicon.  For some reason the timer never gets fired.
I've tried removing the splashscreen and threads but it still won't fire.
The tutorial works ... why doesn't this:


#!/perl -w

use strict;
use warnings;
$|=1;

use Win32::GUI;
use Win32::GUI::SplashScreen;

use threads;
use threads::shared;
use Thread::Queue;

## Create worker threads and associated variables.
## -- THIS MUST BE DONE, AND ALL THREADS STARTED
## -- BEFORE THE WINDOW IS CREATED.
my $TQ1 = new Thread::Queue;
my $TQ2 = new Thread::Queue;

my $ts1_run : shared = 0;
my $ts2_run : shared = 0;

my $t1_objHandle : shared = 0;
my $t2_objHandle : shared = 0;

my $thread1 = threads->new(\&Thread1);
my $thread2 = threads->new(\&Thread2);


## Hide Perl Window
my $perlW = Win32::GUI::GetPerlWindow();
#Win32::GUI::Hide($perlW);


# Create and diaplay the splash screen
Win32::GUI::SplashScreen::Show(
 -file      => "splash.bmp",  # set a name that doe not exist to force
internal splash screen
 -mintime   => 3,
);


# Hide the splash - blocks until the splashscreen is removed
Win32::GUI::SplashScreen::Done();


## Create Window
my $win = new Win32::GUI::Window(
        -name  => 'winMain',
        -title  => "My Main Window",
       -size   => [700, 500],
       -onResize => \&resizeWin,
);
my $t1 = $win->AddTimer('T1', 1000); # never calls sub T1_Timer

$win->AddButton(
        -name   => 'btnRun1',
        -size   => [50,20],
        -pos    => [4,10],
        -text   => 'Run 1',
);

$win->AddProgressBar(
        -name   => 'pbT1',
        -size   => [120,20],
        -pos    => [58,10],
        -smooth => 1,
);
$win->{pbT1}->SetRange(0,99);
$t1_objHandle = $win->{pbT1}->{-handle};

$win->AddButton(
        -name   => 'btnRun2',
        -size   => [50,20],
        -pos    => [4,32],
        -text   => 'Run 2',
);

$win->AddProgressBar(
        -name   => 'pbT2',
        -size   => [120,20],
        -pos    => [58,32],
        -smooth => 1,
);
$win->{pbT2}->SetRange(0,99);
$t2_objHandle = $win->{pbT2}->{-handle};

my $sb = $win->AddStatusBar();

my $icon = new
Win32::GUI::Icon('d:/source/perl/auditutil/images/data_server.ICO');
my $ni = $win->AddNotifyIcon(
        -name => "NI",
        -icon => $icon,
        -tip => "Hello"
);

$win->Center();
$win->Show();
Win32::GUI::Dialog();



#### Boss
sub winMain_Maximize{ 0 };
sub winMain_Minimize{ 0 };
sub winMain_Resize{ 0 };
sub winMain_Terminate{
 $ts1_run = -1;
 $ts2_run = -1;
 #join workers.
 $thread1->join();
 $thread2->join();
 $win->NI->Remove();
 $win->Hide();
 return -1;
}

sub btnRun1_Click{
 print "clicked btnRun1 \n";
 if($ts1_run){
  $win->{btnRun1}->Text('Run 1');
  $ts1_run = 0;
 }else{
  $win->{btnRun1}->Text('Stop 1');
  $ts1_run = 1;
 }
 return 1;
}

sub btnRun2_Click{
 if($ts2_run){
  $win->{btnRun2}->Text('Run 2');
  $ts2_run = 0;
 }else{
  $win->{btnRun2}->Text('Stop 2');
  $ts2_run = 1;
 }
 return 1;
}

sub resizeWin {
 $sb->Move(0, $win->ScaleHeight - $sb->Height);
 $sb->Resize($win->ScaleWidth, $sb->Height);
}

sub T1_Timer {
 print "Timer went off!\n";
 return 0;
}

#### Child 1
sub Thread1{
 my $ctr = 1;
 while( $ts1_run != -1 ){ # die when semaphore says so.
  if( $ts1_run == 1  && defined($t1_objHandle) ){ #only create a new value
when the semaphore is Up
   Win32::GUI::ProgressBar::SetPos($t1_objHandle, $ctr);
   $ctr++;
   $ctr = 0 if $ctr > 99;
  }
  select(undef, undef, undef, 0.01);
 }
}

#### Child 2
sub Thread2{
 my $ctr = 1;
 while( $ts2_run != -1 ){ # die when semaphore says so.
  if( $ts2_run == 1 && defined($t1_objHandle) ){ #only create a new value
when the semaphore is Up
   Win32::GUI::ProgressBar::SetPos($t2_objHandle, $ctr);
   $ctr++;
   $ctr = 0 if $ctr > 99;
  }
  select(undef, undef, undef, 0.01);
 }
}
Thanks in advance,
Brian Fredette
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to