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

Getting handle of TreeViewItem

Expand Messages
  • Tim Mitchell
    Hello, I m trying to use Piotr s example 2.6 in Chapter 2. GUI testing - tutorial to find the handle of an item in a TreeView using SendMessage with
    Message 1 of 1 , Jul 10 9:52 AM
    • 0 Attachment
      Hello,

      I'm trying to use Piotr's example 2.6 in "Chapter 2. GUI testing -
      tutorial" to find the handle of an item in a TreeView using
      SendMessage with TVM_GETITEM. This is just the first step in using
      TVM_GETITEMRECT to find the screen coordinates of the item so that I
      can move the mouse cursor and click on it. I'm not a C or C++
      programmer.

      Here is what I've come up with so far.

      50 my $TreeHandle = shift;
      51 SetFocus($TreeHandle);
      52 my $ItemHandle = "0"; #Initialized
      53 my $tvItemString = shift;
      54 my $tvItemString_ptr = pack('P', $tvItemString);
      55 my $tvitem = AllocateVirtualBuffer($TreeHandle, 200);
      56 my $text_buf = AllocateVirtualBuffer($TreeHandle, 200);
      57 print "ItemHandle: $ItemHandle\n";
      58 print "tvItemString_ptr: $tvItemString_ptr\n";
      59 my $str_buf = pack("L L L L L L L L L L",
      60 0, #mask
      61 $ItemHandle->{'ItemHandle_ptr'}, #Handle of tvitem we
      are trying to find
      62 0, #state
      63 0, #stateMask
      64 0, #pszText
      65 48, #cchTextMax
      66 0, #iImage
      67 0, #iSelectedImage
      68 0, #cChildren
      69 $tvItemString_ptr->{'ptr'}, #lParam value
      70 );
      71
      72 WriteToVirtualBuffer($tvitem, $str_buf);
      73 #$TVM_GETITEM = 0x110C
      74 SendMessage($TreeHandle, 0x110C, 0, $tvItem->
      {'ItemHandle_ptr'});
      75
      76 my $value = ReadFromVirtualBuffer( $ItemHandle, 200 );
      77 # $value =~ s/^(\w+)(.*)/$1/;
      78 FreeVirtualBuffer( $tvitem );
      79 FreeVirtualBuffer( $text_buf );
      80 print "The TreeViewItem handle is $value\n";

      The error output indicates that I have failed to initialize both
      $ItemHandle and $tvItemString_ptr when in fact the console output
      shows that $ItemHandle has indeed been initialized to 0. I can't do
      better than that because this is the value I am trying to find. Line
      54 is where I have set $tvItemString_ptr to a pointer (I think). The
      print statement result shows this result to be garbage.

      Error output:
      Use of uninitialized value in pack at
      C:/Perl/site/lib/SMTpats/TKS.pm line 59.
      Use of uninitialized value in pack at
      C:/Perl/site/lib/SMTpats/TKS.pm line 59.
      Use of uninitialized value in subroutine entry at
      C:/Perl/site/lib/SMTpats/TKS.pm line 70.
      Can't use string ("0") as a HASH ref while "strict refs" in use at
      C:/Perl/site/lib/Win32/GuiTest.pm line 910.

      Console output:
      ItemHandle: 0
      tvItemString_ptr: ´Õ

      Since clicking on and finding items in a TreeView are so basic to
      testing my software, I have been stuck at this point for several
      days. Can anyone help me find the system handle of an item in a
      TreeView?

      Oh, and one other question. Is it possible to use the full path to
      the tree item, as found by GetTreeViewSelPath, for the string,
      $tvItemString, pointed to by the last argument of the C structure
      that begins at line 59?

      Thank you for any help.

      Tim Mitchell
    Your message has been successfully submitted and would be delivered to recipients shortly.