Re: [perl-win32-gui-users] looping in win32 GUI
christopher sagayam wrote: I might be slow to learn but Actually what Im concerned about is the while loop How do I get out of the while loop ? while ( ($status, $status_text) = RasGetConnectStatus($hrasconn) ) { } once the control goes into this loop how it is going to get out ? Or are these kinds of daemons possible in Win32::GUI ? as I already said, it depends on your application. and I also add, it depends on your Perl programming style :-) a possible way could be: $stay_in_loop = 1; while ( $stay_in_loop ) { ($status, $status_text) = RasGetConnectStatus($hrasconn) or $stay_in_loop = 0; # ...body of the loop... $MainWindow-DoEvents(); } at this point, you could have for example a 'Stop' button which can control the loop like this: sub Stop_Click { $stay_in_loop = 0; } but you may prefer a different approach... cheers, Aldo __END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print;
Re: [perl-win32-gui-users] looping in win32 GUI
Thanks aldo I will use DO event but in case there is a better solution do keep me posted Here is what Im trying to do I am trying to write a win32 gui perl client which when started will check whether the computer is connected to internet continuously indefinety in the meantime other actions should proceed also So based on your previous example actually there wont be a STOP button at all since this loop is going to be continuouly executed as along as the win32 gui script is running now the catch is during the time the loop is running I need to catch key presses , button presses , tab presses etc too and do it efficiently Thanks chris - Original Message - From: Aldo Calpini [EMAIL PROTECTED] To: christopher sagayam perl-win32-gui-users@lists.sourceforge.net Sent: Wednesday, February 14, 2001 3:47 PM Subject: Re: [perl-win32-gui-users] looping in win32 GUI christopher sagayam wrote: $|=1; use Win32::RASE; eval use Time::HiRes qw(sleep); $hrasconn = (RasEnumConnections())[1]; $old_status = -1; while ( ($status, $status_text) = RasGetConnectStatus($hrasconn) ) { if ($status != $old_status) { print $status: $status_text\n; $old_status = $status; } sleep ($@ ? 1 : 0.01); } # error 6 - Invalid handle ($err = Win32::RASE::GetLastError) != 6 and die Win32::RASE::FormatMessage($err); exit; The above code goes into a while loop and constantly checks for the internet connection and prints connected or disconnected as appropriate Now my question is how do I use this loop in Win32 GUI well, it depends on the design of your application. basically, the Right Way is to use DoEvents. DoEvents is similar to Dialog, in the sense that it looks for keypresses, mouse clicks, etc. and fires the appropriate event(s). the big difference is that DoEvents does not loop, like Dialog, until it receives a termination message. instead, if there's nothing to process, DoEvents returns immediately. you can call DoEvents inside the loop like this: while ( ($status, $status_text) = RasGetConnectStatus($hrasconn) ) { if ($status != $old_status) { print $status: $status_text\n; $old_status = $status; } sleep ($@ ? 1 : 0.01); $MainWindow-DoEvents(); } this way your application can have a 'Stop' button that may, for example, break the loop (not *immediately* responsive, but better than nothing :-). the loop could be embedded in an event sub (for example, StartCheck_Click), or you can have no Win32::GUI::Dialog at all, so that the above loop is the real 'core' of the script. as I said, it depends on the design of your application. if this is not clear, please elaborate a bit more about the program you're trying to write. cheers, Aldo __END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print; ___ Perl-Win32-GUI-Users mailing list Perl-Win32-GUI-Users@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
Re: [perl-win32-gui-users] looping in win32 GUI
christopher sagayam wrote: Here is what Im trying to do I am trying to write a win32 gui perl client which when started will check whether the computer is connected to internet continuously indefinety in the meantime other actions should proceed also So based on your previous example actually there wont be a STOP button at all since this loop is going to be continuouly executed as along as the win32 gui script is running now the catch is during the time the loop is running I need to catch key presses , button presses , tab presses etc too and do it efficiently I see. in this case, the best thing to do is to setup a Timer object with a small interval and do your connectivity test once inside its Timer event, no loop, no sleep :-) cheers, Aldo __END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print;
Re: [perl-win32-gui-users] looping in win32 GUI
Thanks aldo for all your info chris www.perl-resume.com - Original Message - From: Aldo Calpini [EMAIL PROTECTED] To: christopher sagayam perl-win32-gui-users@lists.sourceforge.net Sent: Wednesday, February 14, 2001 6:59 PM Subject: Re: [perl-win32-gui-users] looping in win32 GUI christopher sagayam wrote: Here is what Im trying to do I am trying to write a win32 gui perl client which when started will check whether the computer is connected to internet continuously indefinety in the meantime other actions should proceed also So based on your previous example actually there wont be a STOP button at all since this loop is going to be continuouly executed as along as the win32 gui script is running now the catch is during the time the loop is running I need to catch key presses , button presses , tab presses etc too and do it efficiently I see. in this case, the best thing to do is to setup a Timer object with a small interval and do your connectivity test once inside its Timer event, no loop, no sleep :-) cheers, Aldo __END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print; ___ Perl-Win32-GUI-Users mailing list Perl-Win32-GUI-Users@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com