Update of /cvsroot/perl-win32-gui/Win32-GUI/Win32-GUI-AxWindow/demos
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22088/demos

Added Files:
        DHtmlEdit.pl InfoControl.pl MShtml.pl Movie.avi 
        MovieControl.pl MsFlexGrid.pl SCGrid.pl TestOLE.pl 
        WMPControl.pl WebBrowser.pl WebBrowser2.pl 
Log Message:
Merge AxWindow into core distribution

--- NEW FILE: MsFlexGrid.pl ---
#!perl -w
use strict;
use warnings;

#
# Hosting MsFlexGrid : Test Indexed properties
# You need a computer with a registered version of MSFlxgrd.ocx
# (e.g. with a VC++ installation) to run this demo
#
# Sadly if you don't have a registered version of msflxgrd.ocx
# you don't get a control creation failure, but an IE window
# showing an error, as the underlying framework assumes that
# "MSFlexGridLib.MSFlexLib" is a URL to try any load!
#

use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::GUI::AxWindow();

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Win32::GUI::AxWindow test",
    -pos      => [100, 100],
    -size     => [400, 400],
    -name     => "Window",
    -addstyle => WS_CLIPCHILDREN,
) or die "new Window";

# Create AxWindow
my $Control = new Win32::GUI::AxWindow  (
    -parent  => $Window,
    -name    => "Control",
    -pos     => [0, 0],
    -size    => [400, 400],
    -control => 'MSFlexGridLib.MSFlexGrid',
 ) or die "new Control";

# Test Enum property set by string value
# $Control->SetProperty("ScrollBars", "flexScrollBarNone");
# $Control->SetProperty("GridLines", "flexGridInset");

$Control->SetProperty("Rows", 5);
$Control->SetProperty("Cols", 5);

#$Control->SetProperty("TextMatrix", 1, 2, "Hello!!!");

#my $r = $Control->GetProperty("Rows");
#my $c = $Control->GetProperty("Cols");
#my $t = $Control->GetProperty("TextMatrix", 1, 2);
#print "Rows = $r, Cols = $c, TextMatrix(1,2) = $t\n";

# Event loop
$Window->Show();
Win32::GUI::Dialog();
$Window->Hide();
exit(0);

# Main window event handler

sub Window_Resize {
    if (defined $Window) {
        my ($width, $height) = ($Window->GetClientRect)[2..3];
        $Control->Resize ($width, $height);
    }
}

--- NEW FILE: Movie.avi ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: WebBrowser.pl ---
#!perl -w
use strict;
use warnings;

#
#  Hosting a WebBrowser
#    Create a WebBrowser and register an event.
#    Enumerate Property, Methods and Events and create a Html file.
#    Load Html file in WebBrowser.
#

use File::Temp();
use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::GUI::AxWindow();

# main Window
my $Window = Win32::GUI::Window->new(
    -title => "Win32::GUI::AxWindow WebBrowser",
    -pos   => [100, 100],
    -size  => [400, 400],
    -name  => "Window",
    -pushstyle => WS_CLIPCHILDREN,
) or die "new Window";

# Create AxWindow
my $Control = new Win32::GUI::AxWindow  (
    -parent  => $Window,
    -name    => "Control",
    -pos     => [0, 0],
    -size    => [400, 400],
    -control => "Shell.Explorer.2",
#   -control => "{8856F961-340A-11D0-A96B-00C04FD705A2}",
 ) or die "new Control";

# Register Event

$Control->RegisterEvent("StatusTextChange",
        sub {
            my($self,$id, @args) = @_;
            print "Event : ", @args, "\n";
        }
);

# Enum Property info

my $tmp = File::Temp->new(SUFFIX => ".html");
print "writing to file: $tmp\n";

print $tmp "<html>\n";
print $tmp "<head><title>AxWindow WebBrowser Properties</title></head>\n";
print $tmp "<body><hr /><h1>Properties</h1><hr />\n";

foreach my $id ($Control->EnumPropertyID()) {
    my %property = $Control->GetPropertyInfo ($id);

    print $tmp "<p>\n";
    foreach my $key (keys %property) {
        print $tmp "<b>$key</b> = $property{$key}<br />\n";
    }
    print $tmp "</p>\n";
}

# Enum Method info

print $tmp "<hr /><h1>Methods</h1><hr />\n";

foreach my $id ($Control->EnumMethodID()) {
    my %method = $Control->GetMethodInfo ($id);

    print $tmp "<p>\n";
    foreach my $key (keys %method) {
        print $tmp "<b>$key</b> = $method{$key}<br />\n";
    }
    print $tmp "</p>\n";
}

# Enum Event info

print $tmp "<hr /><h1>Events</h1><hr />\n";

foreach my $id ($Control->EnumEventID()) {
    my %event = $Control->GetEventInfo ($id);

    print $tmp "<p>\n";
    foreach my $key (keys %event) {
        print $tmp "<b>$key</b> = $event{$key}<br />\n";
    }
    print $tmp "</p>\n";
}

print $tmp "</body></html>\n";

# Method call
my $path = "file://$tmp";

# print $path, "\n";
$Control->CallMethod("Navigate", $path);

# Event loop
$Window->Show();
Win32::GUI::Dialog();
$Window->Hide();
exit(0);

# Main window event handler

sub Window_Resize {
    if (defined $Window) {
        my ($width, $height) = ($Window->GetClientRect)[2..3];
        $Control->Resize ($width, $height);
    }
}

--- NEW FILE: DHtmlEdit.pl ---
#!perl -w
use strict;
use warnings;

#
#  Hosting DHtmlEdit basic 
# You can't do much with it!  See DHtmlEditor.pl
# for a better sample (using Win32::GUI::DHtmlEdit)
#

use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::GUI::AxWindow();

# main Window
my $Window = new Win32::GUI::Window(
    -name     => "Window",
    -title    => "Win32::GUI::AxWindow test",
    -pos      => [100, 100],
    -size     => [400, 400],
    -addstyle => WS_CLIPCHILDREN,
) or die "new Window";

# Create AxWindow
my $Control = new Win32::GUI::AxWindow(
    -parent  => $Window,
    -name    => "Control",
    -pos     => [0, 0],
    -size    => [400, 400],
    -control => "DHTMLEdit.DHTMLEdit",
   #-control => "{2D360200-FFF5-11D1-8D03-00A0C959BC0A}",
) or die "new Control";

# Method call
$Control->CallMethod("NewDocument");

# Event loop
$Window->Show();
Win32::GUI::Dialog();
$Window->Hide();
exit(0);

# Main window event handler

sub Window_Terminate {
    # Print Html Text
    print $Control->GetProperty("DocumentHTML");

    return -1;
}

sub Window_Resize {
    if (defined $Window) {
        my ($width, $height) = ($Window->GetClientRect)[2..3];
        $Control->Move(0, 0);
        $Control->Resize($width, $height);
    }
}

--- NEW FILE: MovieControl.pl ---
#!perl -w
use strict;
use warnings;

#
#  Hosting Movie Control (A movie player control see
#  http://www.viscomsoft.com/movieplayer.htm)
#
# A 30-day trial licence of the control is available from
# the above site.
#

use FindBin();
use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::GUI::AxWindow();

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Movie Control Test",
    -pos      => [100, 100],
    -size     => [200, 200],
    -name     => "Window",
    -addstyle => WS_CLIPCHILDREN,
) or die "new Window";

# Add a play button
$Window->AddButton(
        -name => "Button",
        -text => 'Play',
        -pos  => [10,10],
);

# Create AxWindow
my $Control = new Win32::GUI::AxWindow  (
    -parent  => $Window,
    -name    => "Control",
    -pos     => [0, $Window->Button->Height()+20],
    -width   => $Window->ScaleWidth(),
    -height  => $Window->ScaleHeight()-$Window->Button->Height()-20,
#   -control => "{F4A32EAF-F30D-466D-BEC8-F4ED86CAF84E}",
    -control => "MOVIEPLAYER.MoviePlayerCtrl.1",
) or die "new Control";

# Load Avi file
$Control->SetProperty("FileName", "$FindBin::Bin/movie.avi");

# Event loop
$Window->Show();
Win32::GUI::Dialog();
$Window->Hide();
exit(0);

# Main window event handler

sub Window_Resize {
  if (defined $Window) {
      my ($width, $height) = ($Window->GetClientRect)[2..3];
      $height = $height - $Window->Button->Height() - 20;
      #$Control->Resize ($width, $height);
      $Control->CallMethod("ResizeControl", $width, $height);
  }
}

sub Button_Click {
    # Start Avi player
    $Control->CallMethod("Play");
}

--- NEW FILE: SCGrid.pl ---
#!perl -w
use strict;
use warnings;

#
# Hosting SCGrid (A freeware Grid ActiveX see : http://www.scgrid.com/)
# Download SCGridLite from http://www.scgrid.com/
# - Extract SCGrid.ocx and put it somewhere
# - from the command prompt: regsvr32 <path_to>\SCGrid.ocx
# - (uninstall regsvr32 /u <path_to>\SCGrid.ocx, and delete SCGrid.ocx)
#

use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::GUI::AxWindow();

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Win32::GUI::AxWindow test",
    -pos      => [100, 100],
    -size     => [400, 400],
    -name     => "Window",
    -addstyle => WS_CLIPCHILDREN,
) or die "new Window";

# Create AxWindow
my $Control = new Win32::GUI::AxWindow  (
    -parent  => $Window,
    -name    => "Control",
    -pos     => [0, 0],
    -size    => [400, 400],
    -control => "prjSCGrid.SCGrid",
 ) or die "new Control";

# Redraw Off
$Control->SetProperty("Redraw", 0);

# Create 1 Fixed col and Row
$Control->SetProperty("FixedRows", 1);
$Control->SetProperty("FixedCols", 1);
# Create 5 col and Row
$Control->SetProperty("Rows", 5);
$Control->SetProperty("Cols", 5);
# Adjust grid on column
$Control->SetProperty("AdjustLast", "scColumn");
# Add Resize column mode
$Control->SetProperty("ResizeMode", "scColumn");

# Fill Cell
for my $C (0..4)
{
    for my $R (0..4)
    {
        $Control->SetProperty("Text", $R, $C, "Cell ($R, $C)");
    }
}

# Fill Fixed Rows
$Control->SetProperty("Text", -1, -1, "    ");
for my $R (0..4)
{
    $Control->SetProperty("Text", $R, -1, "$R");
}
#$Control->CallMethod("AdjustWidth", -1, -32767);  # Force optional value

# Fill Fixed Cols and adjust size
for my $C (0..4)
{
    $Control->SetProperty("Text", -1, $C, "FixedCol($C)");
    #$Control->CallMethod("AdjustWidth", $C, -32767); # Force optional value
}

# Enable draw mode
$Control->SetProperty("Redraw", 1);

# Some property get
my $r = $Control->GetProperty("Rows");
my $c = $Control->GetProperty("Cols");
my $t = $Control->GetProperty("Text", 1, 2);
print "Rows = $r, Cols = $c, Text(1,2) = $t\n";

# Event loop
$Window->Show();
Win32::GUI::Dialog();

# Main window event handler

sub Window_Resize {
    if (defined $Window) {
        my ($width, $height) = ($Window->GetClientRect)[2..3];
        $Control->Move   (0, 0);
        $Control->Resize ($width, $height);
    }
}

--- NEW FILE: TestOLE.pl ---
#!perl -w
use strict;
use warnings;

#
#  Host with AxWindow and manipulate with Win32::OLE
#  - Use GetOLE
#  - Call method
#  - Write in a HTML document
#

use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::OLE();
use Win32::GUI::AxWindow();

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Win32::GUI::AxWindow and Win32::OLE",
    -pos      => [100, 100],
    -size     => [600, 600],
    -name     => "Window",
    -addstyle => WS_CLIPCHILDREN,
) or die "new Window";

# A button
my $Button = $Window->AddButton (
    -name => "Button",
    -pos  => [0, 25],
    -size => [600, 50],
    -text => "Click me !!!",
    );

# Create AxWindow
my $Control = new Win32::GUI::AxWindow  (
    -parent  => $Window,
    -name    => "Control",
    -pos     => [0, 100],
    -size    => [600, 500],
    -control => "Shell.Explorer.2",
 ) or die "new Control";

# Get Ole object
my $OLEControl = $Control->GetOLE();

# $OLEControl->Navigate("about:blank");  # Clear control
$OLEControl->Navigate("http://www.google.com/";);

# Event loop
$Window->Show();
Win32::GUI::Dialog();
$Window->Hide();
exit(0);

# Button Event
sub Button_Click {
    $OLEControl->{Document}->{body}->insertAdjacentHTML("BeforeEnd","Click 
!!!");
    #print "HTML = ", $OLEControl->{Document}->{body}->innerHTML, "\n";
    return 0;
}

# Main window event handler

sub Window_Resize {
    if (defined $Window) {
        my ($width, $height) = ($Window->GetClientRect)[2..3];
        $Button->Width($width);
        $Control->Resize($width, $height-100);
    }
}

--- NEW FILE: WebBrowser2.pl ---
#!perl -w
use strict;
use warnings;

#
#  Hosting a WebBrowser
#    Create a WebBrowser and register an event.
#    Enumerate Property, Methods and Events and display in WebBrowser.
#  Same demo as WebBrowser.pl, but using OLE to avoid the temp file.
#

use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::GUI::AxWindow();
use Win32::OLE();

# main Window
my $Window = Win32::GUI::Window->new(
    -title => "Win32::GUI::AxWindow WebBrowser",
    -pos   => [100, 100],
    -size  => [400, 400],
    -name  => "Window",
    -pushstyle => WS_CLIPCHILDREN,
) or die "new Window";

# Create AxWindow
my $Control = new Win32::GUI::AxWindow  (
    -parent  => $Window,
    -name    => "Control",
    -pos     => [0, 0],
    -size    => [400, 400],
    -control => "Shell.Explorer.2",
 ) or die "new Control";

# Enum Property info

my $html = "";
$html .= "<html>\n";
$html .= "<head><title>AxWindow WebBrowser Properties</title></head>\n";
$html .= "<body><hr /><h1>Properties</h1><hr />\n";

foreach my $id ($Control->EnumPropertyID()) {
    my %property = $Control->GetPropertyInfo ($id);

    $html .= "<p>\n";
    foreach my $key (keys %property) {
        $html .= "<b>$key</b> = $property{$key}<br />\n";
    }
    $html .= "</p>\n";
}

# Enum Method info

$html .= "<hr /><h1>Methods</h1><hr />\n";

foreach my $id ($Control->EnumMethodID()) {
    my %method = $Control->GetMethodInfo ($id);

    $html .= "<p>\n";
    foreach my $key (keys %method) {
        $html .= "<b>$key</b> = $method{$key}<br />\n";
    }
    $html .= "</p>\n";
}

# Enum Event info

$html .= "<hr /><h1>Events</h1><hr />\n";

foreach my $id ($Control->EnumEventID()) {
    my %event = $Control->GetEventInfo ($id);

    $html .= "<p>\n";
    foreach my $key (keys %event) {
        $html .= "<b>$key</b> = $event{$key}<br />\n";
    }
    $html .= "</p>\n";
}

$html .= "</body></html>\n";

# Load blank page
$Control->CallMethod("Navigate", "about:blank");
# write the HTML to the page
$Control->GetOLE()->{Document}->write($html);

# free memory
undef $html;

# Event loop
$Window->Show();
Win32::GUI::Dialog();
$Window->Hide();
exit(0);

# Main window event handler

sub Window_Resize {
    if (defined $Window) {
        my ($width, $height) = ($Window->GetClientRect)[2..3];
        $Control->Resize ($width, $height);
    }
}

--- NEW FILE: InfoControl.pl ---
#!perl -w
use strict;
use warnings;

#
# Application to display control information, demosntrating AxWindow
# usage for Webbrowser, as well as providing useful information for
# anyone wanting to use other controls
#
# If you're randomly browsing controls, don't be surprised to find some
# that crash perl.
#
# Select an AxtiveX Object from the dropdown ...
#
# Author: Robert May
#

use Win32::GUI qw(WS_CLIPCHILDREN WS_EX_CLIENTEDGE);
use Win32::GUI::AxWindow();
use Win32::OLE();
use Win32::TieRegistry();

# Info about the currently inspected control
my %INFO;

# main Window
my $mw = new Win32::GUI::Window (
    -name     => "MW",
    -title    => "Win32::GUI::AxWindow Control Navigator",
    -size     => [600,400],
    -addstyle => WS_CLIPCHILDREN,
    -onResize => \&mwResize,
) or die "new Window";
$mw->Center();

$mw->AddLabel(
    -name   => "PROGID_Prompt",
    -pos    => [10,13],
    -height => 20,
    -text   => "Select PROGID :",
) or die "new Label";

$mw->AddCombobox(
    -name     => "PROGID",
    -top      => 10,
    -left     => $mw->PROGID_Prompt->Left()+$mw->PROGID_Prompt->Width()+10,
    -size     => [300,200],
    -vscroll  => 1,
    -onChange => \&loadInfo,
    -dropdownlist => 1,
) or die "new Combobox";

$mw->AddTreeView(
    -name        => 'TV',
    -top         => $mw->PROGID_Prompt->Height()+20,
    -width       => 180,
    -height      => $mw->ScaleHeight()-$mw->PROGID_Prompt->Height()-20,
    -rootlines   => 1,
    -lines       => 1,
    -buttons     => 1,
    -onNodeClick => \&dispInfo,
) or die "new TreeView";

Win32::GUI::AxWindow->new(
    -parent     => $mw,
    -control    => "Shell.Explorer",
    -name       => 'BW',
    -left       => $mw->TV->Left() + $mw->TV->Width()+5,
    -top        => $mw->PROGID_Prompt->Height()+20,
    -width      => $mw->ScaleWidth()-$mw->TV->Width()-5,
    -height     => $mw->ScaleHeight()-$mw->PROGID_Prompt->Height()-20,
    -addexstyle => WS_EX_CLIENTEDGE,
) or die "new AxWindow";

# Load a blank page
$mw->BW->CallMethod("Navigate", "about:blank");

$mw->Show();
$mw->Disable();

# Ref to list of controls
my $controls = getInstalledControls();
exit(0) if not defined $controls;  # Abort

#Populate combo selection
$mw->PROGID->Add(sort {lc $a cmp lc $b} @{$controls});

$mw->Enable();
$mw->BringWindowToTop();
Win32::GUI::Dialog();
$mw->Hide();
undef $mw;
exit(0);

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

    $win->TV->Height($height-$win->TV->Top());

    $win->BW->Width($width-$win->BW->Left());
    $win->BW->Height($height-$win->BW->Top());

    return 1;
}

sub loadInfo {
    Update_Treeview($mw->TV);
    return 1;
}

sub Update_Treeview {
    my $tv = shift;

    # reset information
    %INFO = ();
    $tv->DeleteAllItems();
    Display("");

    $INFO{progid} = $mw->PROGID->Text();
    $INFO{progid} =~ s/\s.*$//;

    # Determine if we can create the object:
    # This is pretty heavy handed, but I can't think of a better
    # way to prevent us falling back on Shell.Explorer if we can't
    # load the requested ActiveX object
    {
        my $oleobj;
        {
            local $SIG{__WARN__} = sub {};
            $oleobj = Win32::OLE->new($INFO{progid});
        }
        if (not defined $oleobj) {
            Display("<p style='color:red;'>ERROR creating $INFO{progid} 
(OLE)</p>");
            return 0;
        }
    }

    # Create invisible AxWindow control
    my $C = new Win32::GUI::AxWindow(
        -parent  => $mw,
        -name    => "Control",
        -control => $INFO{progid},
    );
    if (not defined $C) {
        Display("<p style='color:red;'>ERROR creating $INFO{progid} 
(Control)</p>");
        return 0;
    }

    # Get Property info
    foreach my $id ($C->EnumPropertyID()) {
        my %property = $C->GetPropertyInfo($id);
        $INFO{Properties}->{$property{-Name}} = \%property;
    }

    # Get Method info
    foreach my $id ($C->EnumMethodID()) {
        my %method = $C->GetMethodInfo($id);
        $INFO{Methods}->{$method{-Name}} = \%method;
    }

    # Get Event info

    foreach my $id ($C->EnumEventID()) {
        my %event = $C->GetEventInfo ($id);
        $INFO{Events}->{$event{-Name}} = \%event;
    }

    # Update the tree view

    # Insert the nodes
    for my $pnode_text qw(Properties Methods Events) {
        next if not defined $INFO{$pnode_text};

        my $pnode = $tv->InsertItem(-text => $pnode_text);

        for my $prop_name (sort keys %{$INFO{$pnode_text}}) {
            $tv-> InsertItem(
                -parent => $pnode,
                -text   => $prop_name,
            );
        }
    }

    return 1;
}

sub dispInfo {
    my ($tv, $node) = @_;

    my $pnode = $tv->GetParent($node);

    # Don't do anything for the top level nodes
    return 1 if $pnode == 0;

    my %pitem_info = $tv->GetItem($pnode);
    my $type = $pitem_info{-text};

    my %item_info = $tv->GetItem($node);
    my $name = $item_info{-text};

    my $info = $INFO{$type}->{$name};

    my $html;
    if ($type eq "Properties") {
       $html = property_html($info);
    }
    elsif ($type eq "Methods") {
       $html = method_html($info);
    }
    elsif ($type eq "Events") {
       $html = event_html($info);
    }
    else {
       $html = "<p>Unknown type: $type (you shouldn't see this)</p>";
    }

    Display($html);

    return 1;
}

sub Display{
    my $html = shift;

    # Clear the document window and send the new contents
    # Ask Microsoft why they don't support the
    # document.clear method
    $mw->BW->GetOLE()->{Document}->open("about:bank", "_self");
    $mw->BW->GetOLE()->{Document}->write($html);
    $mw->BW->GetOLE()->{Document}->close();
}

sub property_html {
    my $prop = shift;

    my $html = "<h2>Property: $prop->{-Name}</h2>";
    $html .= "<p>$prop->{-Description}</p>";
    $html .= "<table>";
    $html .= "<tr><td>Name:</td><td>$prop->{-Name}</td></tr>";
    $html .= "<tr><td>Prototype:</td><td>$prop->{-Prototype}</td></tr>";
    $html .= "<tr><td>VarType:</td><td>$prop->{-VarType}</td></tr>";
    $html .= 
"<tr><td>Readonly:</td><td>".($prop->{-ReadOnly}?"Yes":"No")."</td></tr>";
    $html .= "<tr><td>ID:</td><td>$prop->{-ID}</td></tr>";
    $html .= "</table>";

    my $enumstr = $prop->{-EnumValue};
    if (length($enumstr) > 0) {
        $html .= "<h3>Enumerated values</h3>";
        $html .= "<table border='1' cellspacing='0'>";
        for my $pair (split /,/, $enumstr) {
            my ($name, $value) = split /=/, $pair;
            $html .= "<tr><td>$name</td><td>$value</td></tr>";
        }
        $html .= "</table>";
    }

    return $html;
}

sub method_html {
    my $prop = shift;

    my $html = "<h2>Method: $prop->{-Name}</h2>";
    $html .= "<p>$prop->{-Description}</p>";
    $html .= "<table>";
    $html .= "<tr><td>Name:</td><td>$prop->{-Name}</td></tr>";
    $html .= "<tr><td>Prototype:</td><td>$prop->{-Prototype}</td></tr>";
    $html .= "<tr><td>ID:</td><td>$prop->{-ID}</td></tr>";
    $html .= "</table>";

    return $html;
}

sub event_html {
    my $prop = shift;

    my $html = "<h2>Event: $prop->{-Name}</h2>";
    $html .= "<p>$prop->{-Description}</p>";
    $html .= "<table>";
    $html .= "<tr><td>Name:</td><td>$prop->{-Name}</td></tr>";
    $html .= "<tr><td>Prototype:</td><td>$prop->{-Prototype}</td></tr>";
    $html .= "<tr><td>ID:</td><td>$prop->{-ID}</td></tr>";
    $html .= "</table>";

    return $html;
}

# Enumerate registry key HKCR\CLSID.  All classes with a 'Control'
# subkey are ActiveX controls
sub getInstalledControls {
    my $abort = 0;
    LoadingWindow::Show($mw);

    my @controls = ();

    my $clsidkey = Win32::TieRegistry->new(
        "HKEY_CLASSES_ROOT/CLSID/",
        { Access => "KEY_READ", Delimiter => '/', }
    );
    my $r = $clsidkey->TiedRef();

    LoadingWindow::SetRange(scalar keys %$r);

    while(my ($key, $value) = each %$r) {
       $abort = LoadingWindow::Step();
       last if $abort;

       # next, unless we have an ActiveX control
       next unless ref($value) and exists $value->{Control};

       my $ProgID = $value->{ProgID}->{'/'};

       # Some controls appear to have an empty name
       next unless defined $ProgID and length $ProgID > 0;

       my $VIProgID = $value->{VersionIndependentProgID}->{'/'};
       $ProgID .= " ($VIProgID)" if defined $VIProgID and length $VIProgID > 0;

       push @controls, $ProgID;
    }
    
    LoadingWindow::Close();
    return $abort ? undef : [EMAIL PROTECTED];
}

# package to wrap the progress bar that we show while
# loading stuff from the registry
package LoadingWindow;
our ($win,$terminate);

# Initialise and show the progress bar mini-window
sub Show {
    my $parent = shift;

    $terminate = 0;

    $win = Win32::GUI::Window->new(
        -parent      => $parent,        
        -title       => "Loading ...",
        -size        => [200,50],
        -toolwindow  => 1,
        -onTerminate => sub {$terminate = 1; 1;},
    ) or die "new Lwindow";
    $win->Center($parent);

    $win->AddProgressBar(
        -name => 'PB',
        -size => [$win->ScaleWidth(),$win->ScaleHeight()],
        -smooth => 1,
    ) or die "new Lprogress";
    $win->PB->SetStep(1);

    $win->Show();
    Win32::GUI::DoEvents();

    return 1;
}

# Set the max ranges of the progress bar
# (to the number of itertations of the
# loop we will do)
sub SetRange {
    $win->PB->SetRange(0, shift) if $win;
    return 1;
}

# Step the progress bar.  Return 1 if we expect
# the caller to abort
sub Step {
    return 1 if $terminate;

    $win->PB->StepIt() if $win;
    Win32::GUI::DoEvents();
    return 0;
}

# Hide the min-window, and free any resources
# it is using;  prepare for it to be used again
sub Close {
    if($win) {
        Win32::GUI::DoEvents();
        $win->Hide();
        Win32::GUI::DoEvents();
        undef $win;
        undef $terminate;
    }
    return 1;
}

--- NEW FILE: WMPControl.pl ---
#!perl -w
use strict;
use warnings;

#
#  Hosting Windows Media Player
#  Needs WMP 7 and above (different object model to WMP 6.4)
#

use FindBin();
use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::GUI::AxWindow();
use Win32::OLE();

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Movie Control Test",
    -pos      => [100, 100],
    -size     => [200, 200],
    -name     => "Window",
    -addstyle => WS_CLIPCHILDREN,
) or die "new Window";

# Add a play button
$Window->AddButton(
        -name => "Button",
        -text => 'Play',
        -pos  => [10,10],
);

# Create AxWindow
my $Control = new Win32::GUI::AxWindow  (
    -parent  => $Window,
    -name    => "Control",
    -pos     => [0, $Window->Button->Height()+20],
    -width   => $Window->ScaleWidth(),
    -height  => $Window->ScaleHeight()-$Window->Button->Height()-20,
    -control => "WMPlayer.OCX",
) or die "new Control";

# Don't autostart the video clip when we load it
$Control->GetOLE()->settings->{autoStart} = 0;

# Remove all ui widgets - just have the video window
# For some reason SetProperty doesn't seem to wrok - use OLE instead
#$Control->SetProperty("uiMode", "none");
$Control->GetOLE()->{uiMode} = "none";

# Stretch Video to video window
#$Control->GetOLE()->{stretchToFit} = 1;
$Control->SetProperty("stretchToFit", 1);

# Load the Avi file
$Control->SetProperty("URL", "$FindBin::Bin/Movie.avi");

# Event loop
$Window->Show();
Win32::GUI::Dialog();
$Window->Hide();
exit(0);

# Main window event handler

sub Window_Resize {
  if (defined $Window) {
      my ($width, $height) = ($Window->GetClientRect)[2..3];
      $height = $height - $Window->Button->Height() - 20;
      $Control->Resize ($width, $height);
  }
}

sub Button_Click {
    # Play the AVI file
    $Control->GetOLE()->{controls}->play();
    return 1;
}

--- NEW FILE: MShtml.pl ---
#!perl -w
use strict;
use warnings;

#
#  MSHTML : Load static HTML data
#
#

use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::GUI::AxWindow();

# main Window
my $Window = new Win32::GUI::Window (
    -title => "Win32::GUI::AxWindow MSHTML demo",
    -pos   => [100, 100],
    -size  => [400, 400],
    -name  => "Window",
    -addstyle => WS_CLIPCHILDREN,
) or die "new Window";

# Create AxWindow
my $Control = new Win32::GUI::AxWindow  (
    -parent  => $Window,
    -name    => "Control",
    -pos     => [0, 0],
    -size    => [400, 400],
    -control => "MSHTML:<body>This is a line of text</body>",
) or die "new Control";

# Event loop
$Window->Show();
Win32::GUI::Dialog();
$Window->Hide();
exit(0);

# Main window event handler

sub Window_Resize {
    if (defined $Window) {
        my ($width, $height) = ($Window->GetClientRect)[2..3];
        $Control->Resize ($width, $height);
    }
}


Reply via email to