从窗口复制富文本

时间:2013-01-20 18:18:51

标签: perl copy-paste

我需要在Windows操作系统下从程序窗口复制富文本。

如果我将文本拖放到wordpad中(ctrl-c不起作用),我会使用特定的希腊字体获得正确的结果;但它在perl下根本不起作用。我认为这取决于它是富文本的事实。

在下面的代码中,我尝试了###前面的行的所有可能的排列,结果总是相同的,显示了许多问号,而不是希腊格式的文本。

你能帮忙吗?感谢

use 5.016;
use Win32::GuiTest
qw( FindWindowLike GetWindowRect GetWindowID GetClassName WMGetText GetWindowText UnicodeSemantics);
use strict;
use warnings;
use Encode qw (from_to decode encode);

UnicodeSemantics(1);

###
use open ':encoding(utf8)';
###
#binmode(STDOUT, ":utf8");
###
open 'FILE', ">", "canc.txt";
###
#binmode(FILE, ":utf8");

my $hwnd = 131266;
my $info = "# Window Text: '" . GetWindowText($hwnd) . "'\r\n";
$info = $info . "# Window Class: '" . GetClassName($hwnd) . "'\r\n";
$info = $info . "# Window ID: " . GetWindowID($hwnd) . "\r\n";
my ( $left, $top, $right, $bottom ) = GetWindowRect($hwnd);
$info = $info . "# Window Rect: ($left, $top) - ($right, $bottom)\r\n";

say $info;
my $actualText = WMGetText($hwnd);
say $actualText;
say FILE $actualText;
###
my $foo = decode( 'UTF-8', $actualText );
say $foo;
say FILE $foo;
###
my $body = encode( 'UTF-8', $foo );
say $body;
say FILE $body;

0 个答案:

没有答案