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


Reply via email to