In the spirit of TMTOWTDI, you could also look at the Win32::API module, and do API calls to achieve most anything. There is an online API reference (including messages for the SendMessage API I used) at http://www.vbapi.com
Here's a small example I whipped up to experiment myself. Note that you will have to open Calculator in "scientific mode" for this script to work.
#! C:/perl/bin/perl -w
use strict;
use Win32::API;
use vars qw($rv);
use constant BM_CLICK => hex('F5');
my $findwindow = new Win32::API("user32",
"FindWindowA",
['P','P'],
'N');
my $findwindowex = new Win32::API("user32",
"FindWindowExA",
['N','N','P','P'],
'N');
my $sendmessage = new Win32::API("user32",
"SendMessageA",
['N','N','N','P'],
'N');
my $setactivewindow = new Win32::API("user32",
"SetActiveWindow",
['N'],
'N');
# Find the handle of the parent window. In this case
# 'Calculator' is the text shown in the title bar
my $hwnd = $findwindow->Call( 0,'Calculator');
print "Parent window handle = $hwnd\n";
# Find the handle of the buttons we want to press.
# Sometimes, but not always, the caption shown on the button
my $hex_button = $findwindowex->Call($hwnd, 0, 0, 'Hex');
my $dec_button = $findwindowex->Call($hwnd, 0, 0, 'Dec');
my $oct_button = $findwindowex->Call($hwnd, 0, 0, 'Oct');
my $bin_button = $findwindowex->Call($hwnd, 0, 0, 'Bin');
$rv = $setactivewindow->Call($hwnd);
print "setactivewindow returned = $rv\n";
foreach ($hex_button,$dec_button,$oct_button,$bin_button) {
$rv = $sendmessage->Call($_ , BM_CLICK, 0, 0);
print "sendmessage returned = $rv\n";
sleep 2;
}
ryddler
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.