hello
the following code will add the pictures found in the current directory to a ListBox , then by clicking on any item in the ListBox it will display that picture to a WebBrowser control in a Win32::GUI::AxWindow
the program works okay when we click on any item the first time, but it will not display any other picture in the second click or more.
i think the problem is in :
$OLEControl = $Control->GetOLE();
$OLEControl->Navigate("about:Blank"); # Clear control
which are in the ListBox_Click event
if we comment those lines and add it to a button_click event then every time we need to display a picture we must click that button first then click on an item in the ListBox.
whats the difference between adding it to a click event of ListBox or a Button click?? can some one show me the bugs in this code.
using webbrowsers are especially usefull in displaying correctly the animated Gifs.
thanks
use strict; use warnings; use Cwd; use Win32::GUI qw(WS_VSCROLL WS_VISIBLE); use Win32::OLE; use Win32::GUI::AxWindow; my $dir = getcwd; our $OLEControl; # main Window my $Window = new Win32::GUI::Window ( -title => "Win32::GUI::AxWindow and Win32::OLE", -pos => [0, 0], -size => [620, 470], -name => "Window", ) or die "new Window"; # Create AxWindow our $Control = new Win32::GUI::AxWindow ( -parent => $Window, -name => "Control", -pos => [150, 0], -size => [400, 400], -control => "Shell.Explorer.2", ) or die "new Control"; my $PicList = $Window->AddListbox( -name => "PicList", -top => 0, -left => 0, -width => 125, -height => 110, -addstyle => WS_VISIBLE | 3 | WS_VSCROLL, ); #the button are for test only $Window->AddButton( -name => "display", -align => "left", -text => "Display", -left => 0, -top => 200, -width => 100, -height => 50, ); opendir DH, $dir or die "Cannot open $dir: $!"; my @files = grep { ! -d } readdir DH; closedir DH; #choose only jpg or gif files my @picFiles = grep /.+\.jpg|gif/,@files; # work with @files foreach my $item (@picFiles) { $PicList->Add($item); } #the following button just for test only sub display_Click { $OLEControl = $Control->GetOLE(); $OLEControl->Navigate("about:Blank"); # Clear control } #Show application window $Window->Show(); #Enter event loop Win32::GUI::Dialog(); #Hide windows on exit $Window->Hide(); undef $Window; exit(0); sub PicList_Click { my $ListSelection = $PicList->SelectedItem(); my $selectedPic = $PicList->GetString($ListSelection); my $picture = $dir . '/' . $selectedPic; # Get Ole object $OLEControl = $Control->GetOLE(); $OLEControl->Navigate("about:Blank"); # Clear control my $pic = "<html><body><img src='$picture' /></body></html>"; $OLEControl->{Document}->write($pic); # Write Html return 0; } # Main window event handler sub Window_Terminate { # Release all before destroy window undef $OLEControl; $Control->Release(); return -1; } sub Window_Resize { if (defined $Window) { my($width, $height) = ($Window->GetClientRect)[2..3]; $Control->Resize ($width, $height); } } __END__

In reply to picture browser using WebBrowser by glassy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.