-Shanthi
Otherwise, NodeClick will return a node object as one of
the parameters in the event.
Can you be more specific?
D.
"Shanthi" <s...@srasys.co.in> wrote in message
news:#ep$0lssBHA.2524@tkmsftngp04...
Thanks for your reply. Here I have explained my problem
properly.
I want to show one popup menu during right clicking of a node in a Treeview.
In Treeview - MouseUp event using PopupMenu I am able to display the popup
menu in a correct (Current mousepointer location) location. Because MouseUp
event gives the mouse pointer current location (X,Y) so that we can display
the Menu based on the X,Y Values.
The same functionlity I want to do it through keyboard also.
In the KeyDown event I can catch the equivalent (RightClick) key & using the
Popup Menu method I can display the Popup Menu. In the above case I know the
X,Y values. Here I am unable to get it. It is not showing the Popup in the
proper location. I tried "GetCursorPos" to get X, Y values. It is returing
the same values for all the nodes. I need to get the X,Y Co-ordinates of the
currently selected node.
How can I get the X,Y co-ordinates of the currently selected node?
Hope I am clear now.
Expecting your suggestion.
Regards,
-Shanthi
"dnagel" <Grand...@hotmail.com> wrote in message
news:eYTs$xssBHA.1740@tkmsftngp04...
--
Randy Birch
MVP Visual Basic
Please respond only to the newsgroups so all can benefit.
*** If you call the Sleep API in Bill's latest, will it have .NET dreams?
***
"Shanthi" <s...@srasys.co.in> wrote in message
news:eOxdOCRtBHA.2052@tkmsftngp07...
Am i clear?
"Randy Birch" <r...@mvps.org> wrote in message
news:eodfHWRtBHA.1672@tkmsftngp04...
'***** Begin Copy *****
Option Explicit
Private Const TV_FIRST = &H1100
Private Const TVM_GETITEMRECT = (TV_FIRST + 4)
Private Const TVM_GETNEXTITEM = (TV_FIRST + 10)
Private Const TVGN_CARET = &H9
Private Const TVGN_ROOT = &H0
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 Function GetSelectedNodeCoords( _
tvwTree As MSComctlLib.TreeView) As RECT
Dim hNode As Long
Dim rcBox As RECT
If Not tvwTree.SelectedItem Is Nothing Then
'Node must be fully visible to get coords.
tvwTree.SelectedItem.EnsureVisible
'Get a handle to the currently selected node
hNode = SendMessage(tvwTree.hWnd, _
TVM_GETNEXTITEM, TVGN_CARET, ByVal TVGN_ROOT)
'Set the first four bytes (Long) of the
'rect to the handle of the node, before
'calling TVM_GETITEMRECT.
rcBox.Left = hNode
'Get the coordinates of the node
If SendMessage(tvwTree.hWnd, _
TVM_GETITEMRECT, True, rcBox) = 0 Then
'Zero the rect to show failure
With rcBox
.Left = 0
.Top = 0
.Right = 0
.Bottom = 0
End With
End If
End If
'Return the rect
GetSelectedNodeCoords = rcBox
End Function
'***** End Copy *****
***** Sample to call this Code: *****
Private Sub Command1_Click()
Dim rcBox As RECT
rcBox = GetSelectedNodeCoords(tvwMain)
With rcBox
If .Right > 0 Then
Debug.Print .Left, .Top, .Right, .Bottom
Else
Debug.Print "Failed to retrieve coordinates"
End With
End Sub
***** End Sample Code *****
Rocky Clark (Kath-Rock Software)
"Shanthi" <s...@srasys.co.in> wrote in message
news:#ep$0lssBHA.2524@tkmsftngp04...
Add the End If in this section of code.
With rcBox
If .Right > 0 Then
Debug.Print .Left, .Top, .Right, .Bottom
Else
Debug.Print "Failed to retrieve coordinates"
End If
End With
Sorry about that,
Rocky
"Rocky Clark" <so...@nosuchluck.com> wrote in message
news:mwZa8.159256$jO5.18...@typhoon.tampabay.rr.com...
> 'Get a handle to the currently selected node
> hNode = SendMessage(tvwTree.hWnd, _
> TVM_GETNEXTITEM, TVGN_CARET, ByVal TVGN_ROOT)
You only need to specify the message's lParam when using
a flag that returns an item handle relative to the lParam, as in:
TVGN_CHILD
TVGN_NEXT
TVGN_PREVIOUS
TVGN_PARENT
TVGN_NEXTVISIBLE
TVGN_PREVIOUSVISIBLE.
The message's the lParam is ignores for the flags that return an
"absolute" item handle:
TVGN_FIRSTVISIBLE
TVGN_CARET
TVGN_DROPHILITE
TVGN_ROOT
The treeview's pre-defined macros prevents this potential confusion
while making things much more readable...
Public Function TreeView_GetNextItem(hwnd As Long, hItem As Long, flag As Long) As Long
TreeView_GetNextItem = SendMessage(hwnd, TVM_GETNEXTITEM, ByVal flag, ByVal hItem)
End Function
Public Function TreeView_GetSelection(hwnd As Long) As Long
TreeView_GetSelection = TreeView_GetNextItem(hwnd, 0, TVGN_CARET)
End Function
--
Brad Martinez, http://www.mvps.org
Please direct questions/replies to the newsgroup
Thanks a lot for your timely help. It is working fine.
-Regards
Shanthi
"Rocky Clark" <so...@nosuchluck.com> wrote in message
news:mwZa8.159256$jO5.18...@typhoon.tampabay.rr.com...
Rocky
"Brad Martinez" <bt...@msn.com.nospam> wrote in message
news:u6veD4ctBHA.1652@tkmsftngp03...