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

Re: Select Item in Listbox

Expand Messages
  • Piotr Kaluski
    You are right, it is not there. Win32::GuiTest does not have a full coverage of all operations for all common controls. So you may find more missing
    Message 1 of 4 , Feb 19, 2006
    • 0 Attachment
      You are right, it is not there.
      Win32::GuiTest does not have a full coverage of all operations for all
      common controls. So you may find more missing functionalities, which
      are seen as natural.
      If you have some programming skills have a look at guitest.xs file.
      Programming some basic operations for common controls is pretty
      straightforward.
      As for now you can work around this problem using SendKeys. I agree it
      is not the most elegant solution, but it works.

      --Piotr


      --- 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?
      >
    • brentje
      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
      Message 2 of 4 , Feb 23, 2006
      • 0 Attachment
        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:
        http://www.piotrkaluski.com/files/winguitest/docs/ch09s74.html
        For the pack/unpack commands, see:
        http://www.perl.com/doc/manual/html/pod/perlfunc/pack.html
        and
        http://www.perl.com/doc/manual/html/pod/perlfunc/unpack.html
        For Microsoft's standard control reference for Listboxes, visit:
        http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listboxes/listboxes.asp

        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",
        0,
        0,
        0,
        0,
        );

        $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);
        SendMouse('{LEFTCLICK}');
        }

        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.

        Brent



        --- 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?
        >
      • 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 3 of 4 , Feb 23, 2006
        • 0 Attachment
          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", "" );
          SetFocus($selectitemID[0]);
          @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 ) );
          }

          Tim


          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:
          http://www.piotrkaluski.com/files/winguitest/docs/ch09s74.html
          For the pack/unpack commands, see:
          http://www.perl.com/doc/manual/html/pod/perlfunc/pack.html
          and
          http://www.perl.com/doc/manual/html/pod/perlfunc/unpack.html
          For Microsoft's standard control reference for Listboxes, visit:
          http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listboxes/listboxes.asp

          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",
          0,
          0,
          0,
          0,
          );

          $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);
          SendMouse('{LEFTCLICK}');
          }

          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.

          Brent



          --- 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?
          >






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

          ---------------------------------
          YAHOO! GROUPS LINKS


          Visit your group "perlguitest" on the web.

          To unsubscribe from this group, send an email to:
          perlguitest-unsubscribe@yahoogroups.com

          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.