Not sure about refreshing the listview. But to get some more control between
events you can try adding 

        $MainWin->Update();
        $MainWin->DoEvents();

into sub ScanButton_Click. I tried it just above your InvalidateRect line
and it seemed to work pretty well. You should definitely add the -tabstop
arg to your textboxes.

You can search the maillist archive at
http://aspn.activestate.com/ASPN/Mail/ or even a decent google search will
give similar results. Try
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=perl+win32+gui+li
stview

Good Luck,
Pete


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Thursday, March 20, 2003 1:17 PM
To: perl-win32-gui-users@lists.sourceforge.net
Subject: [perl-win32-gui-users] Refresh Listview


Hello,

I have a windows with a listview.  The windows takes in a range of ip
addresses, then click on a button and scans them.  The results are put in a
listview.  When the scan is running the window becomes unresponsive and the
listview is only updated after the scan is complete.  Two questions.  How
do I get the listview to update after each entry?  How do I keep the window
from becomming locked so I can a "stop" button to stop the scan?

Thanks,
Joe

PS:  I'm sure this has been covered before but where are archives kept.

Here is my code:
#!/usr/bin/perl
use LWP::Simple;
use Win32::GUI;

$Font = new Win32::GUI::Font(
     -name   => "Times New Roman",
     -height => 16,
);

$Menu = new Win32::GUI::Menu(
     "&File"   => "File",
     " > &Save as" => "Saveas",
     " > &Exit" => "Exit",
  );

$MainWin = new Win32::GUI::Window(
     -name   => "MainWin",
     -text   => "Web Query",
     -width  => 500,
     -height => 325,
     -left   => 100,
     -top    => 100,
     -menu     => $Menu,
     -font   => $Font,
);

$Netaddra = $MainWin->AddTextfield(
     -name     => "Netaddra",
     -prompt => ["IP Address", 75],
     -left   => 10,
     -top    => 10,
     -width  => 30,
     -height => 25,
);

$Netaddrb = $MainWin->AddTextfield(
     -name   => "Netaddrb",
     -prompt => [".", 5],
     -left   => 115,
     -top    => 10,
     -width  => 30,
     -height => 25,
);

$Netaddrc = $MainWin->AddTextfield(
     -name     => "Netaddrc",
     -prompt => [".", 5],
     -left   => 155,
     -top    => 10,
     -width  => 30,
     -height => 25,
);

$Netaddrstart = $MainWin->AddTextfield(
     -name     => "Netaddrstart",
     -prompt => [".", 5],
     -left   => 190,
     -top    => 10,
     -width  => 30,
     -height => 25,
);

$Netaddrfinish = $MainWin->AddTextfield(
     -name     => "Netaddrfinish",
     -left   => 195,
     -top    => 40,
     -width  => 30,
     -height => 25,
);

$LabelStart = $MainWin->AddLabel(
     -name => "LabelStart",
     -text => "- Start",
     -left => 225,
     -top  => 15,
);

$LabelFinish = $MainWin->AddLabel(
     -name => "LabelFinish",
     -text => "- Finish",
     -left => 225,
     -top  => 45,
);

$Netaddra->MaxLength(3);
$Netaddrb->MaxLength(3);
$Netaddrc->MaxLength(3);
$Netaddrstart->MaxLength(3);
$Netaddrfinish->MaxLength(3);

$MainWin->AddButton(
     -name   => "ScanButton",
     -text   => "SCAN",
     -align  => center,
     -valign => center,
     -left   => 350,
     -top    => 10,
);

$MainWin->AddListView(
     -name     => "ListView",
     -text     => "Results",
     -left     => 10,
     -top => 75,
     -width    => 470,
     -height   => 200,
     -style    => WS_CHILD | WS_VISIBLE | 1,
  );

$MainWin->ListView->InsertColumn(
     -index    => 0,
     -text     => "IP Address",
  );

$MainWin->ListView->InsertColumn(
     -index    => 1,
     -text     => "Web Server",
  );

$MainWin->ListView->ColumnWidth(0, 150);
$MainWin->ListView->ColumnWidth(1, -2);

$MainWin->Show();

Win32::GUI::Dialog();

sub MainWin_Terminate {
    return -1;
}

sub ScanButton_Click {

  $netaddr = $Netaddra->Text() . "." . $Netaddrb->Text() . "." .
$Netaddrc->Text(). ".";
  $start = $Netaddrstart->Text();
  $finish = $Netaddrfinish->Text();

  for($i = $start; $i <= $finish; $i++) {
    $ipaddr = $netaddr . $i;

    $item = $MainWin->ListView->InsertItem(
     -item => $MainWin->ListView->Count(),
     -text => $ipaddr,
    );

    $MainWin->ListView->InvalidateRect(1);

    if(!($server = (head("http://$ipaddr";))[4])) {
     $server = "N/A";
    }

    $MainWin->ListView->SetItem(
     -item    => $item,
     -subitem => 1,
     -text    => $server,
    );
  }
}

sub Saveas_Click {

  $ret = GUI::GetSaveFileName(
     -title  => "Win32::GUI::GetSaveFileName test",
     -file   => "\0" . " " x 256,
     -filter => [
          "CSV (Comma delimited)(*.csv)" => "*.csv",
          "All files", "*.*",
     ],
  );

  if($ret) {
    print "GetSaveFileName returned: '$ret'\n";
    $fname = $ret . ".csv";
    SaveOutput($fname);
  } else {
    if(GUI::CommDlgExtendedError()) {
        print "ERROR. CommDlgExtendedError is: ", GUI::CommDlgExtendedError
(), "\n";
    } else {
        print "You cancelled.\n";
    }
  }
}

sub SaveOutput {
  open(OUT,">$_[0]");

  my $rowcount = $MainWin->ListView->Count();
  my $columncount = 2;

  print "Row: ", $rowcount, " Column: ", $columncount, "\n";

  print OUT '"'. "IP Address" .'",';
  print OUT '"'. "Web Server" .'",';
  print OUT "\n";

  for($i = 0; $i < $rowcount; $i++) {
    for(my($y) = 0; $y <= $columncount; $y++) {
      my(@value) = $MainWin->ListView->ItemInfo($i,$y);
      print OUT '"'.$value[1].'",';
    }
    print OUT "\n";
  }
  close(OUT);
}

sub Exit_Click {
  MainWin_Terminate();
}





-------------------------------------------------------
This SF.net email is sponsored by: Tablet PC.  
Does your code think in ink? You could win a Tablet PC. 
Get a free Tablet PC hat just for playing. What are you waiting for? 
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users

Reply via email to