Loading ...
Sorry, an error occurred while loading the content.

Re: [perlguitest] Re: Select Item in Listbox

Expand Messages
  • Timothy Mitchell
    Thanks for the reply. I did it like this, putting the subroutines in a seperate module for reuse. Select item is the title of a test dialog that has
    Message 1 of 4 , Feb 23, 2006
      Thanks for the reply. I did it like this, putting the subroutines in a seperate module for reuse. "Select item" is the title of a test dialog that has alistbox.

      SelectItem( "test" );

      sub SelectItem {
      my $item = shift;
      my @itemlist;
      my @selectitemID;
      #Wait for the dialog with the listbox to appear.
      sleep 1;
      @selectitemID = FindWindowLike( undef, "Select item", "" );
      @itemlist = FindWindowLike(undef, undef, "ListBox");
      selListboxItem($item, $itemlist[0]);

      sub selListboxItem {
      my $selection = shift;
      my $lb = shift;
      #0x018C is the hex code for the MSDN LB_SELECTSTRING
      my $ptr = pack( 'P', $selection );
      SendMessage( $lb, 0x018C , -1, unpack( 'L!', $ptr ) );


      brentje <brentje@...> wrote:
      Yup...that's something that I discovered after I started using
      GuiTest. Not hard to do in yor script if you have the listbox's
      handle, but it would be nice to build into the .XS file eventually as
      Piotr mentioned. In the meantime, here's what I came up with. Keep
      in mind that I prefer to do as much as possible with mouse clicks to
      simulate a user as closely as possible. There are other ways to write
      this out, but you'll still have to use the SendMessage and pack/unpack
      commands in any case.

      You can read more on GuiTest's SendMessage command at:
      For the pack/unpack commands, see:
      For Microsoft's standard control reference for Listboxes, visit:

      sub SetListboxValue
      my $H_ListBox = shift;
      my $s_FieldValue = shift;

      my $i_Index;

      my $S_SearchBuffer;
      my $p_Search;

      #Create a C compliant variable that ends with a null character
      #for the search, and send the LB_SELECTSTRING message to the
      #field. The value of LB_SELECTSTRING is 0x018C. This will
      #highlight the item you're looking for, and bring it into view
      #if it's not currently visible. Note that this does NOT cause
      #any events to fire, so if there is an OnClick event for the
      #listbox you'll have to manually click that item before anything #happens.
      $s_FieldValue = $s_FieldValue . "\0";
      $S_SearchBuffer = pack( 'P', $s_FieldValue );
      $p_Search = unpack( 'L!', $S_SearchBuffer );
      $i_Index = SendMessage( $H_ListBox, LB_SELECTSTRING(), -1,
      $p_Search );

      if($i_Index < 0)
      return 0;

      undef $S_SearchBuffer;
      undef $p_Search;

      #Re-use the SearchBuffer to hold the coordinates of the item.
      $S_SearchBuffer = pack( "LLLL",

      $p_Search = unpack( 'L!', pack( 'P', $S_SearchBuffer ) );

      #Get the items's coordinates. The value of LB_GETITEMRECT is 0x0198.
      if(SendMessage( $H_ListBox, LB_GETITEMRECT , $i_Index, $p_Search )
      > -1)
      my ($i_LeftX, $i_TopY, $i_RightX, $i_BottomY) = unpack(
      'LLLL', $S_SearchBuffer );

      #Find the middle of the item, convert to absolute screen coordinates,
      #and click on the item.
      my $i_ClientX = $i_LeftX + (int(($i_RightX - $i_LeftX)/2));
      my $i_ClientY = $i_TopY + (int(($i_BottomY - $i_TopY)/2));

      my ($i_X, $i_Y) = ClientToScreen( $H_ListBox, $i_ClientX,
      $i_ClientY );

      MouseMoveAbsPix($i_X, $i_Y);

      return 1;

      This should give you a good start for selecting listbox items. Keep
      in mind there's lot of information out there, and that it would
      probably be good to write it into the .XS file if you have the time
      and energy.


      --- In perlguitest@yahoogroups.com, "Tim Mitchell" <maxquig@...> wrote:
      > Hi everyone,
      > I have just recently installed Win32-GuiTest on my computer at work. I
      > plan to use Perl and Win32-GuiTest as the basis for running scripts to
      > automate tseting of our software that we write and market. I seem to
      > have quickly run into a fatal flaw in GuiTest. There is no function to
      > select an item from a Listbox. Without this function I am afraid that
      > I will have to just give up the whole idea. Maybe there are other
      > missing functions as well.
      > Does anyone know of a way to do do this?

      Basic programming language C programming language Computer programming languages The c programming language C programming language List of programming languages


      Visit your group "perlguitest" on the web.

      To unsubscribe from this group, send an email to:

      Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.