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;



Reply via email to