Jump to content

Getting the position of a TreeViewItem or ListViewItem


QA Stooge
 Share

Recommended Posts

The title says it all.

Is there some function or set of functions that allows one to query a position (x,y) and get a TreeViewItem or ListViewItem control (ControlID) returned?

How about the other way around: query a TreeViewItem or ListViewItem (ControlID) and it returns a position (x,y)?

Link to comment
Share on other sites

Well, in my code, I have it set up so that at any time, I can get any ControlID, it's type, it's Winhandle, and any applicable parent (such as which ListView is the "parent" of a ListViewItem) or list of "children".

Other than that, the ListViewItem and TreeViewItem controls are generated by Auto-it functions (and after being generated, it's tracked as above).

Link to comment
Share on other sites

Well, in my code, I have it set up so that at any time, I can get any ControlID, it's type, it's Winhandle, and any applicable parent (such as which ListView is the "parent" of a ListViewItem) or list of "children".

Other than that, the ListViewItem and TreeViewItem controls are generated by Auto-it functions (and after being generated, it's tracked as above).

for listview you might want to look for LVM_GETITEMPOSITION and/or LVM_GETITEMRECT, you can find info about them at MSDN

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

TVM_GETITEMRECT looks like it may be useful for what I want. The second parameter (prc) seems to require coordinates.

TVM_HITTEST is sweet, in that it seems to allow for figuring out what TVI is at a set of coordinates.

I feel like a chump, but I've never used these UI Control Messages directly. They look very similar to what's used in Auto-It. Is it directly translatable or do I have to make/use a custom UDF to utilize these golden treasures?

Edited by QA Stooge
Link to comment
Share on other sites

You might want take a look at the following:

Case $event = $NM_RCLICK
                    Local Const $TVHT_NOWHERE = 1
                    Local Const $TVHT_ONITEMICON = 2
                    Local Const $TVHT_ONITEMLABEL = 4
                    Local Const $TVHT_ONITEMINDENT = 8
                    Local Const $TVHT_ONITEMBUTTON = 16
                    Local Const $TVHT_ONITEMRIGHT = 32
                    Local Const $TVHT_ONITEMSTATEICON = 64
                    Local Const $TVHT_ABOVE = 256
                    Local Const $TVHT_BELOW = 512
                    Local Const $TVHT_TORIGHT = 1024
                    Local Const $TVHT_TOLEFT = 2048
                    Local Const $TEST = BitOR($TVHT_ONITEMICON, $TVHT_ONITEMLABEL, $TVHT_ONITEMSTATEICON, $TVHT_ONITEMINDENT, $TVHT_ONITEMBUTTON, $TVHT_ONITEMRIGHT)
                    $opt_bak = Opt("MouseCoordMode", 2)
                    $mpos = MouseGetPos()
                    Opt("MouseCoordMode", $opt_bak)
                    $tpos = ControlGetPos("", "", $TreeView)
                    If Not @error Then
                        $x = $mpos[0] - $tpos[0] ;left offset
                        $y = $mpos[1] - $tpos[1]   ;$top offset
                        $hitinfo = DllStructCreate("int;int;uint;uint");not sure if uint or ptr should go here...will look it up..32 bits is 32 bits
                        If Not @error Then
                            DllStructSetData($hitinfo, 1, $x)
                            DllStructSetData($hitinfo, 2, $y)
                            DllStructSetData($hitinfo, 3, 0)
                            DllStructSetData($hitinfo, 4, 0)
                            GUICtrlSendMsg($TreeView, $TVM_HITTEST, 0, DllStructGetPtr($hitinfo))
                            $hit = DllStructGetData($hitinfo, 3);flags returned
                            $i = DllStructGetData($hitinfo, 4);handle
                            $hitinfo = 0   ;DllStructDelete($hitinfo); seems no DllStructDelete in beta version 1.99
                            If BitAND($hit, $TVHT_ONITEMRIGHT) Then Return 0
                            If BitAND($hit, $TEST) = 0 Then Return 0
                            TreeView_RightClick(_GUICtrlTreeViewGetText($TreeView, $i))
                        EndIf
                    EndIf
Just in case you haven't gotten the memo already, you're a god.

I'm curious, though... how do you know HITTEST is +17?

Edited by QA Stooge
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...