2

我正在努力控制一个 IE 预览控件,它是带有 perl 的外部 Windows 应用程序上的“Internet Explorer_Server”类。

Internet Explorer_Server 是窗口的类名,我用 Spy++ 找到了它。这是我的断言代码

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

我可以使用 获取那个“Internet Explorer_Server”的句柄Win32::GUI::GetWindow,但不知道下一步该做什么。

4

3 回答 3

5

更新:你走错了路。你需要的是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__

因此,此代码找到一个具有Document属性的窗口并打印 HTML。您必须决定要使用什么标准来查找您感兴趣的窗口。

ShellWindows文档

于 2009-07-27T17:01:32.873 回答
1

您可能想看看Win32::IE::Mechanize。我不确定您是否可以使用此模块控制现有的IE 窗口,但应该可以在大约五行代码中访问单个 URL。

于 2009-07-28T07:12:17.360 回答
0

你看过 Samie http://samie.sourceforge.net/因为这是一个控制 IE 的 perl 模块

于 2009-07-27T19:41:07.547 回答