X-Y Coordinates of node on Treeview without using mouse click/ Keystrokes

How can I find the X-Y Co-ordinates
of a particular node on a treeview without using mouse click/ Keystrokes?
SelesAsked:
Who is Participating?
 
amebaConnect With a Mentor Commented:
' add treeview, paste this code
Option Explicit
Private Const TV_FIRST = &H1100
Private Const TVM_GETITEMRECT = (TV_FIRST + 4)
Private Const TVM_GETNEXTITEM = (TV_FIRST + 10)
Private Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub Form_Click()
    Dim ret As Long, rc As RECT, hitem As Long
    ' GetTVItemFromNode function is complex
    '    see: 'Treeview node <-> item handle demo'
    '    http://www.mvps.org/btmtz/treeview/
    'hitem = GetTVItemFromNode(TreeView1.hwnd, TreeView1.Nodes(Key))
   
    ' root is simple :)
    hitem = SendMessage(TreeView1.hwnd, TVM_GETNEXTITEM, ByVal 0&, ByVal 0&)
   
    rc.Left = hitem
    ret = SendMessage(TreeView1.hwnd, TVM_GETITEMRECT, 1&, rc)
    MsgBox rc.Left & " " & rc.Right & " " & rc.Top & " " & rc.Bottom
End Sub

Private Sub Form_Load()
    Dim Node1 As Node, i As Integer, j As Integer
    ' fill treeview
    With TreeView1
        For i = 1 To 3
            Set Node1 = .Nodes.Add(, , "Root" & i, "Root" & i)
            For j = 1 To 3
                .Nodes.Add Node1.Index, tvwChild, "Root" & i & "Child" & j, _
                    "Root" & i & "Child" & j
            Next
            Node1.Expanded = True
        Next
    End With
End Sub
0
 
caraf_gCommented:
There is no direct way of doing this, but you could use the HitTest procedure in conjunction with e.g. a binary search routine?
0
 
SelesAuthor Commented:
Thanks. I know there's no direct way to doing that.

I want to raise what API Procedures may help to solve.

My Goal is setting a function to find
X-Y Client Coordinates of a node in the Treeview window by providing the Key of that node at any time.
0
 
SelesAuthor Commented:
Thank You.
It helps me a lot.
0
 
amebaCommented:
Thanks for your points.
0
All Courses

From novice to tech pro — start learning today.