Node Click

GregDuncan
07-19-2003, 01:45 AM
I have a problem with a treeview control.

I want to diferentiate between when the user clicks on the text of the node and the nodes icon so that I can provide different functionality for each.

i looked at using GetCursorPos but because the treeview is indented and could scroll you cant predict a point of reference.

does anyone know how to do this?

I thinking perhaps subclassing but im new to that so not sure what the events would be to trap for.

any feedback welcome.
thanks

GregDuncan
07-19-2003, 02:51 AM
Found how to do this. Posting code here in case anyone has similar problem.

Private Function ClickedText() As Boolean
'called from inside the _NodeClick function
'can therefore assume that a node has been clicked
'what we want to know is what part of the node was clicked
'since the Node is only made of two parts :
'returns true if the TEXT was clicked
'returns false if the IMAGE was clicked

Dim tVI As TVITEM
Dim hItem As Long
Dim Rec As RECT
Dim Point As POINTAPI

'Get the screen position of the cursor
GetCursorPos Point
ScreenToClient TreeView1.hWnd, Point

'Get the coordinates of the node
hItem = SendMessageLong(TreeView1.hWnd, TVM_GETNEXTITEM, TVGN_CARET, ByVal TVGN_ROOT)

'initiate before calling TVM_GETITEMRECT.
Rec.Left = hItem
'Get the coordinates of the node
If SendMessage(TreeView1.hWnd, TVM_GETITEMRECT, True, Rec) = 0 Then
Rec.Left = 0
End If
If PtInRect(Rec, Point.x, Point.y) Then
ClickedText = True
Else
ClickedText = False
End If

End Function

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)

If ClickedText Then
Label1.BackColor = vbGreen
Else
Label1.BackColor = vbRed
End If

End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum