At 14:53 2002-10-08 -0400, Hawley, Eric wrote:
>Okay I have been attempting to add a timer to a message box and have been
>unsuccessful in being able to do so.  I want to have it so that after the
>message box displays the user has 10 seconds to either click YES or NO with
>default as YES.  If after 10 seconds the user has failed to make a selection
>YES will be automatically choosen. can someone help me out with this. Down
>below is some code that I have from the script.

I would be surprised it that compiled and ran. This does.


#!/usr/bin/perl -w
use strict;
use Win32::GUI;


my $winDummy = Win32::GUI::Window->new(-name => "winApp");  #Create, but 
never Show() it
my $timTimeout = $winDummy->AddTimer( "timTimeout", 10000 );    #10 sec

my $choise = Win32::GUI::MessageBox($winDummy, q {Windows could not finish 
a system task and needs to restart.

NOTE: You MUST reboot Windows so that this task may finish.
Reboot Windows now?},
         "Error", MB_YESNO | MB_ICONINFORMATION | MB_DEFBUTTON1);

print "choice: ($choise)\n";
shutdownWindows() if($choise == 6); #6 seems to be YES



sub timTimeout_Timer {
     print "Timeout...\n";

     #Disable the timer, otherwise it will trigger this event
     #handler again
     $timTimeout->Kill();

     #Never to return
     shutdownWindows();
}

sub shutdownWindows {
     print "do your Windows reboot stuff here, then exit the app\n";

     #This is the downside. You have to exit the Perl script
     #for the dialog box to disappear (I think, please prove me
     #wrong someone!).
     exit(0);
}


__END__

Interesting note: We never call Win32::GUI::Dialog(), and the timer still 
works.

An alternative would be to create the dialog box yourself. That way it's 
like any Win32::GUI::Window, and you can close it the normal way. That's 
what I'd do, but if this brute force solution works for you...


/J

-------- ------ ---- --- -- --  --  -    -     -      -         -
Johan Lindström    Sourcerer @ Boss Casinos     [EMAIL PROTECTED]

Latest bookmark: "SQLite An Embeddable SQL Database Engine"
http://www.hwaci.com/sw/sqlite/
dmoz (1 of 6): ...puters/Software/Configuration_Management/Tools/ 26


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to