Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Automation Problem with Win32::GUI and Win32::GUITest

by talwyn (Monk)
on Mar 17, 2004 at 01:49 UTC ( [id://337193]=perlquestion: print w/replies, xml ) Need Help??

talwyn has asked for the wisdom of the Perl Monks concerning the following question:

I am automating an external program with the modules mentioned in the title of this query. I am using Win32::GUI in a non-owned windows format.

Everything is fine until I get to a point where I need to read some information from the other app's listview control. When I attempt to retrieve an item from the listview the source app crashes. A dialog comes up and proclaims that an error has occurred and that a log will be written. The alleged log is, however, an empty text file.

The offending code is : <more>

sub Select_Tapes ($@) { my $wh_DataCopier = shift; Win32::Sleep(700); my @handles = FindWindowLike ( $wh_DataCopier,"List1", undef ,unde +f); my $listview = $handles[0]; print "List view is at $listview \n"; print "There are :". Win32::GUI::ListView::Count($listview)."Tapes + listed in the Listview\n";
my %tape = Win32::GUI::ListView::GetItem($listview,0); # This line causes the program at handle #$wh_DataCopier to crash the perl script runs along just fine until it realizes there isn't a program to talk to anymore.
print "The First Item is $tape{'-text'}\n"; my @tapes = qw( 000001 000002 000003 000004 ); foreach $tape (@tapes) { my $tapeid=Win32::GUI::Combobox::FindString($listview,$tape); ($tapeid>0) ? print "Found a Tape $tape is index $tapeid\n": +print "Did not find tape $tape\n"; Win32::GUI::Combobox::Select($listview,$tapeid); }
UPDATE Win32::GUI ver .670 for perl 5.6

Replies are listed 'Best First'.
Re: Automation Problem with Win32::GUI and Win32::GUITest
by talwyn (Monk) on Jun 02, 2005 at 04:58 UTC
    Well it turns out that a Solution in C was required. Windows automagically supplies shared memory for the original 16 bit controls.

    Listboxes, however are 32 bit controls!!! So I had to implement the select function to allocate, use and deallocate memory inside the foreign process.

    Here is the bare bones perl module and XS code I used. Sorry about the long time between updates ... but school and work interfere.

    If you like this or use it and want to donate you can paypal me at Steven_swenson@sbcglobal.net. I can always use pizza/gas money :) I attached the code below:

Re: Automation Problem with Win32::GUI and Win32::GUITest
by talwyn (Monk) on Mar 19, 2004 at 00:14 UTC
    I have Further Investigated the problem and it seems the underlying problem is something in SendMessage from the API? I tried to write my own routine to retrieve the information I want. I get precisely the same results as with the WIN32::GUI Module, that is: Retrieving the item count works but attempting to retrieve the item text results in GPF in recieving App. Any Windows API C gurus out there that can point me in the right direction? Am I passing a bad parameter? I want to retrieve the displayed text of the first item of the first row in the first column. ( Not the headers )

    Snippet requires Win32::API

    sub ListView_GetItem ( $$ ) { # ( $wh_Handle, $RowIndex ) #constants use constant LVIF_TEXT => 0x01; use constant LVM_GETITEMCOUNT => 0x1004; use constant LVM_GETITEM => 0x1005; #LVM_FIRST +5 #types typedef Win32::API::Struct _LV_ITEM => qw( UINT mask; int iItem; int iSubItem; UINT state; UINT stateMask; LPTSTR pszText; int cchTextMax; int iImage; LPARAM lParam; ); #Vars my $handle = shift; my $index = 0; my %Item = {}; #Hash to hold Item info my $LV_Item = Win32::API::Struct->new ( '_LV_ITEM'); $Lv_Item->{mask} = LVIF_TEXT; $Lv_Item->{iItem} = 0; $Lv_Item->{iSubItem} = 1; #LRESULT SendMessage( # # HWND hWnd, // handle of destination window # UINT Msg, // message to send # WPARAM wParam, // first message parameter # LPARAM lParam // second message parameter # ); #LVM_GETITEM #wParam = 0; #lParam = (LPARAM) (LV_ITEM FAR*) pitem; Win32::API->Import( 'USER32', 'LRESULT SendMessage( HWND hWnd, UINT Msg, WPARAM wP +aram, LPARAM lParam)' ) || die "fAILED TO IMPORT sENDmESSAGE\n"; #works Fine $items = SendMessage ($handle,LVM_GETITEMCOUNT,0,0); print "Sendmessage saw $items items\n"; #Causes GPF in Recipient SendMessage ($handle,LVM_GETITEM,0,$Lv_Item) || die "Message Faile +d $!\n"; $text = chop $Lv_Item->{pszText}; print "The text is $text \n!"; return $text; }
      You could try later versions of Win32::GUITest that includes better support for listviews. Try looking on www.cpan.org for the latest module.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://337193]
Approved by Vautrin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-26 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found