views:

506

answers:

3

I am struggling to get control of an IE preview control which is 'Internet Explorer_Server' class on an external windows application with perl.

Internet Explorer_Server is the class name of the window, I've found it with Spy++. and here’s my assertion code of it

$className = Win32::GUI::GetClassName($window); 
if ($className eq "Internet Explorer_Server") { 
    ... 
}

I can get a handle of that 'Internet Explorer_Server' with Win32::GUI::GetWindow, but have no idea what to do next.

+3  A: 

Updated: You are going down the wrong path. What you need is Win32::OLE.

#!/usr/bin/perl

use strict;
use warnings;

use Win32::OLE;
$Win32::OLE::Warn = 3;

my $shell = get_shell();
my $windows = $shell->Windows;

my $count = $windows->{Count};

for my $item ( 1 .. $count ) {
    my $window = $windows->Item( $item );
    my $doc = $window->{Document};
    next unless $doc;
    print $doc->{body}->innerHTML;
}

sub get_shell {
    my $shell;
    eval {
        $shell = Win32::OLE->GetActiveObject('Shell.Application');
    };

    die "$@\n" if $@;

    return $shell if defined $shell;

    $shell = Win32::OLE->new('Shell.Application')
        or die "Cannot get Shell.Application: ",
               Win32::OLE->LastError, "\n";
}
__END__

So, this code finds a window with a Document property and prints the HTML. You will have to decide on what criteria you want to use to find the window you are interested in.

ShellWindows documentation.

Sinan Ünür
thanks, but that's not exactly what I want. I don't want to create a new instance of IE. I want the control of IE already exists.
crowdy
A: 

Have you looked at Samie http://samie.sourceforge.net/ as this is a perl module to control IE

Cheshire Cat
*sigh* Where do I start?Let's ignore that comic strip character on the homepage for a second... Samie is not on CPAN. And when you want to download it, all you get is a zip file with a windows-style installer inside. It's packaged up like a proprietary software component. Speaking of which, on the homepage the license is not shown.
hillu
+1  A: 

You may want to have a look at Win32::IE::Mechanize. I am not sure whether you can control an existing IE window with this module, but accessing a single URL should be possible in about five lines of code.

hillu