Kevin L. Gross wrote:
First off, it is painfully slow. Takes a couple of minutes for
a small file (2K) to display, one line at a time. This can't be
normal for Perl on Windows can it?

That's down to you sleep()ing for 1 second for every line of your file - that's bound to be slow!

Second, no scroll box, even tho the -multiline and -autovscroll
parameters are set to 1.

You need -vscroll

Third, the GUI app disappears completely after the last line is
printed. How do you keep the window (and/or DOS command window)
up and displayed?

Win32::GUI::Dialog()


Isn't there a better way to flow text into a scroll-bar field or
window or dialog or something?

Try this.

Regards,
Rob.
--
Robert May
Win32::GUI, a perl extension for native Win32 applications
http://perl-win32-gui.sourceforge.net/

#!perl -w
use strict;
use warnings;

use Win32::GUI qw(WS_CLIPCHILDREN);

my $mw = Win32::GUI::Window->new(
    -title    => "Read File line by line",
    -pos      => [100,100],
    -size     => [400,300],
    -onResize => \&mwResize,
    -addstyle => WS_CLIPCHILDREN, # prevent some flickering on resize
);

$mw->AddTextfield(
    -name       => "TF",
    -size       => [$mw->ScaleWidth(), $mw->ScaleHeight()-30],
    -readonly   => 1,
    -background => 0xEEEEEE,
    -multiline  => 1,
    -vscroll    => 1
);

$mw->AddButton(
    -name    => 'BT',
    -text    => 'Load file',
    -pos     => [$mw->ScaleWidth()-65, $mw->ScaleHeight()-25],
    -onClick => \&load_file,
);

$mw->Show();
Win32::GUI::Dialog();
$mw->Hide();
exit(0);

sub mwResize {
    my $win = shift;
    my ($width, $height) = ($win->GetClientRect())[2..3];

    # Resize edit control
    $win->TF->Resize($width, $height-30);

    # re-position button
    $win->BT->Move($width-65, $height-25);

    return 0;
}

sub load_file {
    my $retval = 0;

    my $file = $0; # This perl script

    open my $fh, '<', $file or die "Failed to open $file for reading";

    while (<$fh>) {
        chomp $_; $_ .= "\r\n";   # Ensure win32 line endings

        # Add text to end of edit control
        $mw->TF->SetSel(-1,-1);  # set selection point to the end
                                 # of the edit control
        $mw->TF->ReplaceSel($_); # replace selection with
                                 # additional text

        # DoEvents: draws the added text, and allows gui interaction
        # in case this takes a long time
        $retval = Win32::GUI::DoEvents(); # returns -1 if user
                                          # terminates window
        last if $retval == -1;   # user terminated window,
                                 # abort from while{} loop
    }

    close $fh;

    return $retval; # return -1 to exit Win32::GUI::Dialog()
}
__END__



Reply via email to