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

Re: move the mouse to the node of a TreeView

Expand Messages
  • brentje
    I ve been looking into similar things regarding TreeView. Haven t written code for it yet, but the info it out there. The MSDN, while a little confusing at
    Message 1 of 7 , Mar 31, 2006
    • 0 Attachment
      I've been looking into similar things regarding TreeView. Haven't
      written code for it yet, but the info it out there. The MSDN, while a
      little confusing at times, is your friend. Take a look at
      TVM_GETITEM, using the TVIF_STATE flag for TVITEM. You can use that
      to get the selected item. Feed the handle it returns into
      TVM_GETITEMRECT, and you should be good to go.

      Here's the links you'll need:

      TVM_GETITEM Message
      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/messages/tvm_getitem.asp

      TVITEM Struct
      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/structures/tvitem.asp

      Tree-View Control Item States
      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/item_states.asp

      --- In perlguitest@yahoogroups.com, "Tim Mitchell" <maxquig@...> wrote:
      >
      > He guys,
      >
      > TVM_GETITEMRECT requires the handle of the item in the tree that you
      > want to find the coordinates of. Winspy doesn't show any child
      > windows belonging to the SysTreeView32. FindWindowLike also doesn't
      > find any child windows. How can I make SendMessage work with
      > TVM_GETITEMRECT to get the coordinates of the selected item on a
      > tree so that I can tell the mouse click where to go?
      >
      > Tim
      > --- In perlguitest@yahoogroups.com, "Piotr Kaluski" <pkaluski@>
      > wrote:
      > >
      > > Hi,
      > > I believe that the message TVM_GETITEMRECT could be something you
      > are
      > > looking for. If you are more experienced in perl you can try my
      > > advanced tutorial
      > > (http://www.piotrkaluski.com/files/winguitest/docs/ch02s04.html)
      > on
      > > how to send such a message.
      > >
      > > -Piotr
      > >
      > >
      > > --- In perlguitest@yahoogroups.com, "ae_hutter"
      > > <Anneliese.Hutter@c...> wrote:
      > > > Hello,
      > > >
      > > > could anybody please help me with a tricky automation challenge?
      > > >
      > > > I need to doubleclick on a node of a TreeView, and do not know
      > how
      > > to
      > > > move the mouse to this node.
      > > >
      > > > I could select the desired node from the tree with
      > Win32::GuiTest
      > > > (which, BTW, is a very great tool) and now I need to doubleclick
      > on
      > > > it. Unfortunately the tested application can only accept a
      > > > doubleclick and not the Enter-key. Therefore I can not use the
      > > > SendKeys function here.
      > > >
      > > > For using SendMouse or MouseClick I need to move the mouse to
      > this
      > > > node. Otherwise it executes the mouse-click on the place where
      > the
      > > > mouse-pointer was before starting the test.
      > > > Is there a way to get the coordinates of the TreeView node at
      > test-
      > > > runtime?
      > > >
      > > > Thanks for any hint,
      > > > Anneliese
      > >
      >
    • kpqt01
      Hello guys, Could someone please show me which is the best way to accomplish this task? - Feed the handle it returns into TVM_GETITEMRECT, and you should be
      Message 2 of 7 , Sep 13, 2006
      • 0 Attachment
        Hello guys,

        Could someone please show me which is the best way to accomplish this
        task? -> "Feed the handle it returns into TVM_GETITEMRECT, and you
        should be good to go."

        1) I able to get the Handle of the select item as follow:

        my $TVM_GETNEXTITEM = 0x1100+10;
        my $TVGN_CARET = 0x0009;
        my $hItem = SendMessage( $Tree_hwnd,$TVM_GETNEXTITEM,$TVGN_CARET,0);
        printf ("handle is: %x\n",$hItem);

        2) And able to verify the handle is correct by get the text of the
        selected item as follow (using advance tutorial):
        my $tvitem = AllocateVirtualBuffer( $Tree_hwnd, 128 );
        my $text_buf = AllocateVirtualBuffer( $Tree_hwnd, 128);
        my $TVIF_STATE =0x0001;
        my $str_buf = pack( "L L L L L L L L L L",
        0x0001, #UINT mask;
        $hItem, #HTREEITEM hItem;
        0, #UINT state;
        0, #UINT stateMask;
        $text_buf->{ 'ptr' }, #LPTSTR pszText;
        128, #int cchTextMax;
        0, #int iImage;
        0, #int iSelectedImage;
        0, #int cChildren;
        0, #LPARAM lParam;
        );

        WriteToVirtualBuffer( $tvitem, $str_buf );
        SendMessage( $Tree_hwnd, 0x1100 + 12, 0, $tvitem->{ 'ptr' } );
        my $text = ReadFromVirtualBuffer( $text_buf, 128);
        $text =~ s/^(\w+)(.*)/$1/;
        FreeVirtualBuffer( $tvitem );
        FreeVirtualBuffer( $text_buf );
        print "Item text is :". $text."\n";

        I am so confuse after read this
        http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/messages/tvm_getitemrect.asp
        from MSDN.

        "the prc parameter contains the handle of the item that the rectangle
        is being retrieved for" <--- How do I do that in perl?

        could someone please show me a way?

        Thanks you in advance,
        kpqt01


        --- In perlguitest@yahoogroups.com, "brentje" <brentje@...> wrote:
        >
        > I've been looking into similar things regarding TreeView. Haven't
        > written code for it yet, but the info it out there. The MSDN, while a
        > little confusing at times, is your friend. Take a look at
        > TVM_GETITEM, using the TVIF_STATE flag for TVITEM. You can use that
        > to get the selected item. Feed the handle it returns into
        > TVM_GETITEMRECT, and you should be good to go.
        >
        > Here's the links you'll need:
        >
        > TVM_GETITEM Message
        >
        http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/messages/tvm_getitem.asp
        >
        > TVITEM Struct
        >
        http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/structures/tvitem.asp
        >
        > Tree-View Control Item States
        >
        http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/item_states.asp
        >
        > --- In perlguitest@yahoogroups.com, "Tim Mitchell" <maxquig@> wrote:
        > >
        > > He guys,
        > >
        > > TVM_GETITEMRECT requires the handle of the item in the tree that you
        > > want to find the coordinates of. Winspy doesn't show any child
        > > windows belonging to the SysTreeView32. FindWindowLike also doesn't
        > > find any child windows. How can I make SendMessage work with
        > > TVM_GETITEMRECT to get the coordinates of the selected item on a
        > > tree so that I can tell the mouse click where to go?
        > >
        > > Tim
        > > --- In perlguitest@yahoogroups.com, "Piotr Kaluski" <pkaluski@>
        > > wrote:
        > > >
        > > > Hi,
        > > > I believe that the message TVM_GETITEMRECT could be something you
        > > are
        > > > looking for. If you are more experienced in perl you can try my
        > > > advanced tutorial
        > > > (http://www.piotrkaluski.com/files/winguitest/docs/ch02s04.html)
        > > on
        > > > how to send such a message.
        > > >
        > > > -Piotr
        > > >
        > > >
        > > > --- In perlguitest@yahoogroups.com, "ae_hutter"
        > > > <Anneliese.Hutter@c...> wrote:
        > > > > Hello,
        > > > >
        > > > > could anybody please help me with a tricky automation challenge?
        > > > >
        > > > > I need to doubleclick on a node of a TreeView, and do not know
        > > how
        > > > to
        > > > > move the mouse to this node.
        > > > >
        > > > > I could select the desired node from the tree with
        > > Win32::GuiTest
        > > > > (which, BTW, is a very great tool) and now I need to doubleclick
        > > on
        > > > > it. Unfortunately the tested application can only accept a
        > > > > doubleclick and not the Enter-key. Therefore I can not use the
        > > > > SendKeys function here.
        > > > >
        > > > > For using SendMouse or MouseClick I need to move the mouse to
        > > this
        > > > > node. Otherwise it executes the mouse-click on the place where
        > > the
        > > > > mouse-pointer was before starting the test.
        > > > > Is there a way to get the coordinates of the TreeView node at
        > > test-
        > > > > runtime?
        > > > >
        > > > > Thanks for any hint,
        > > > > Anneliese
        > > >
        > >
        >
      • brentje
        Ok...that s a good question, since it took me a while to figure out what that the prc parameter contains the handle of the item that the rectangle is being
        Message 3 of 7 , Sep 14, 2006
        • 0 Attachment
          Ok...that's a good question, since it took me a while to figure out
          what that "the prc parameter contains the handle of the item that the
          rectangle is being retrieved for" thing meant too.

          To get the item's RECT values, you need to use SendMessage with the
          TVM_GETITEMRECT message, like this:

          SendMessage( $H_TreeView, TVM_GETITEMRECT() , 1, $o_TreeViewGetRect->{
          'ptr' } )

          Where $H_TreeView is the handle to the TreeView object, the 1 means to
          just grab the coordinates of the text, and $o_TreeViewGetRect->{ 'ptr'
          } is the pointer to the struct holding the 4 RECT variables. Notice
          that we haven't stated which TreeView Item to use yet. We put that in
          the first variable of the $o_TreeViewGetRect struct:

          $S_SearchBuffer = pack( "LLLL",
          $H_TreeViewItem,
          0,
          0,
          0,
          );

          Where $H_TreeViewItem is the handle to the TreeView Item. That's what
          the MSDN site meant. The value will get over-written with the left
          coordinate value. So, all together, you have the handle to the
          TreeView object, the handle to the TreeView Item object, and you want
          to get the item's RECT coordinates:

          my $S_SearchBuffer;

          my $o_TreeViewGetRect = AllocateVirtualBuffer( $H_TreeView, 200 );

          $S_SearchBuffer = pack( "LLLL",
          $H_TreeViewItem,
          0,
          0,
          0,
          );

          WriteToVirtualBuffer( $o_TreeViewGetRect, $S_SearchBuffer );

          if(SendMessage( $H_TreeView, TVM_GETITEMRECT() , 1,
          $o_TreeViewGetRect->{ 'ptr' } ))
          {
          my $o_RectStruct = ReadFromVirtualBuffer( $o_TreeViewGetRect,
          50 );

          my ($i_LeftX, $i_TopY, $i_RightX, $i_BottomY) = unpack( "L4",
          $o_RectStruct );
          }

          I'll let you figure what you want to do from here. And yes, the size
          of my buffer in the AllocateVirtualBuffer may seem large and it
          probably is way too large, but I had enough trouble getting this to
          work in the first place so it stayed. Hope this helps.

          Brent

          --- In perlguitest@yahoogroups.com, "kpqt01" <kpqt01@...> wrote:
          >
          > Hello guys,
          >
          > Could someone please show me which is the best way to accomplish this
          > task? -> "Feed the handle it returns into TVM_GETITEMRECT, and you
          > should be good to go."
          >
          > 1) I able to get the Handle of the select item as follow:
          >
          > my $TVM_GETNEXTITEM = 0x1100+10;
          > my $TVGN_CARET = 0x0009;
          > my $hItem = SendMessage( $Tree_hwnd,$TVM_GETNEXTITEM,$TVGN_CARET,0);
          > printf ("handle is: %x\n",$hItem);
          >
          > 2) And able to verify the handle is correct by get the text of the
          > selected item as follow (using advance tutorial):
          > my $tvitem = AllocateVirtualBuffer( $Tree_hwnd, 128 );
          > my $text_buf = AllocateVirtualBuffer( $Tree_hwnd, 128);
          > my $TVIF_STATE =0x0001;
          > my $str_buf = pack( "L L L L L L L L L L",
          > 0x0001, #UINT mask;
          > $hItem, #HTREEITEM hItem;
          > 0, #UINT state;
          > 0, #UINT stateMask;
          > $text_buf->{ 'ptr' }, #LPTSTR pszText;
          > 128, #int cchTextMax;
          > 0, #int iImage;
          > 0, #int iSelectedImage;
          > 0, #int cChildren;
          > 0, #LPARAM lParam;
          > );
          >
          > WriteToVirtualBuffer( $tvitem, $str_buf );
          > SendMessage( $Tree_hwnd, 0x1100 + 12, 0, $tvitem->{ 'ptr' } );
          > my $text = ReadFromVirtualBuffer( $text_buf, 128);
          > $text =~ s/^(\w+)(.*)/$1/;
          > FreeVirtualBuffer( $tvitem );
          > FreeVirtualBuffer( $text_buf );
          > print "Item text is :". $text."\n";
          >
          > I am so confuse after read this
          >
          http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/messages/tvm_getitemrect.asp
          > from MSDN.
          >
          > "the prc parameter contains the handle of the item that the rectangle
          > is being retrieved for" <--- How do I do that in perl?
          >
          > could someone please show me a way?
          >
          > Thanks you in advance,
          > kpqt01
          >
          >
          > --- In perlguitest@yahoogroups.com, "brentje" <brentje@> wrote:
          > >
          > > I've been looking into similar things regarding TreeView. Haven't
          > > written code for it yet, but the info it out there. The MSDN, while a
          > > little confusing at times, is your friend. Take a look at
          > > TVM_GETITEM, using the TVIF_STATE flag for TVITEM. You can use that
          > > to get the selected item. Feed the handle it returns into
          > > TVM_GETITEMRECT, and you should be good to go.
          > >
          > > Here's the links you'll need:
          > >
          > > TVM_GETITEM Message
          > >
          >
          http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/messages/tvm_getitem.asp
          > >
          > > TVITEM Struct
          > >
          >
          http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/structures/tvitem.asp
          > >
          > > Tree-View Control Item States
          > >
          >
          http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/item_states.asp
          > >
          > > --- In perlguitest@yahoogroups.com, "Tim Mitchell" <maxquig@> wrote:
          > > >
          > > > He guys,
          > > >
          > > > TVM_GETITEMRECT requires the handle of the item in the tree that
          you
          > > > want to find the coordinates of. Winspy doesn't show any child
          > > > windows belonging to the SysTreeView32. FindWindowLike also doesn't
          > > > find any child windows. How can I make SendMessage work with
          > > > TVM_GETITEMRECT to get the coordinates of the selected item on a
          > > > tree so that I can tell the mouse click where to go?
          > > >
          > > > Tim
          > > > --- In perlguitest@yahoogroups.com, "Piotr Kaluski" <pkaluski@>
          > > > wrote:
          > > > >
          > > > > Hi,
          > > > > I believe that the message TVM_GETITEMRECT could be something you
          > > > are
          > > > > looking for. If you are more experienced in perl you can try my
          > > > > advanced tutorial
          > > > > (http://www.piotrkaluski.com/files/winguitest/docs/ch02s04.html)
          > > > on
          > > > > how to send such a message.
          > > > >
          > > > > -Piotr
          > > > >
          > > > >
          > > > > --- In perlguitest@yahoogroups.com, "ae_hutter"
          > > > > <Anneliese.Hutter@c...> wrote:
          > > > > > Hello,
          > > > > >
          > > > > > could anybody please help me with a tricky automation challenge?
          > > > > >
          > > > > > I need to doubleclick on a node of a TreeView, and do not know
          > > > how
          > > > > to
          > > > > > move the mouse to this node.
          > > > > >
          > > > > > I could select the desired node from the tree with
          > > > Win32::GuiTest
          > > > > > (which, BTW, is a very great tool) and now I need to
          doubleclick
          > > > on
          > > > > > it. Unfortunately the tested application can only accept a
          > > > > > doubleclick and not the Enter-key. Therefore I can not use the
          > > > > > SendKeys function here.
          > > > > >
          > > > > > For using SendMouse or MouseClick I need to move the mouse to
          > > > this
          > > > > > node. Otherwise it executes the mouse-click on the place where
          > > > the
          > > > > > mouse-pointer was before starting the test.
          > > > > > Is there a way to get the coordinates of the TreeView node at
          > > > test-
          > > > > > runtime?
          > > > > >
          > > > > > Thanks for any hint,
          > > > > > Anneliese
          > > > >
          > > >
          > >
          >
        • Amit Dixit
          Hi everyone, Can some one explain me about sendmessage API and how can I use it in Perl? Thanks, Amit Dixit
          Message 4 of 7 , Sep 20, 2006
          • 0 Attachment
            Hi everyone,

            Can some one explain me about sendmessage API and how
            can I use it in Perl?

            Thanks,

            Amit Dixit
          Your message has been successfully submitted and would be delivered to recipients shortly.