首先做一个菜单,让他不可见,如:mnuedit,他的子菜单是可见的
然后加这些代码:
Private Sub TreeView1_MouseUp(BUTTON As Integer, Shift As Integer, x As Single, y As Single)
If BUTTON = vbRightButton Then
  If treeview1.HitTest(x, y) Is treeview1.SelectedItem Then
     If Not treeview1.SelectedItem Is Nothing Then
        nodekey = treeview1.SelectedItem.Key ' 获得接点信息
        nodetext = treeview1.SelectedItem.Text
        Me.PopupMenu mnuedit '你的菜单名字
     End If
  End If
End If
End Sub

解决方案 »

  1.   

    http://www.csdn.net/expert/topic/861/861439.xml?temp=.6860926
      

  2.   

    楼上的:zyl910(910:分儿,我来了!) 
    直接把菜单的结构表示在TREEVIEW控件??
    请给个源程序好吗??我哈笨的,看不懂呀!!
      

  3.   

    这个程序是我自己在以前的一个软件中用到的,用的是递归的方式取得窗体的菜单,非常好使。Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Private Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long
    Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As LongPrivate Const MF_BYPOSITION = &H400&''TVPopedom  为TreeView 类型的控件,请自行添加Private Sub Form_Load()
    Dim HMenu as Long
        HMenu = GetMenu(frmMdiMain.hwnd)
        GetMenuAll HMenu, 0, GetMenuItemCount(HMenu), ""
    End SubPrivate Sub GetMenuAll(hMenu As Long, mIndex As Long, mMaxCount As Long, strParent As String)
    Dim mCount          As Long
    Dim mLen            As Long
    Dim hSubMenu        As Long
    Dim strMenu         As String * 255
    Dim strCaption      As String
    Dim nodeX           As MSComctlLib.Node
        hSubMenu = GetSubMenu(hMenu, mIndex)
        mLen = GetMenuString(hMenu, mIndex, strMenu, 255, MF_BYPOSITION)
        strCaption = LeftB(strMenu, mLen)
        If strCaption <> "" Then
            If strParent <> "" Then
                Set nodeX = TVPopedom.Nodes.Add(strParent, tvwChild, strCaption, strCaption)
                nodeX.Expanded = True
            Else
                Set nodeX = TVPopedom.Nodes.Add(, , strCaption, strCaption)
                nodeX.Expanded = True
            End If
        End If
        If mIndex < mMaxCount Then
            mCount = GetMenuItemCount(hSubMenu)
            If mCount > 0 Then
                GetMenuAll hSubMenu, 0, mCount, strCaption ''得到子菜单
            End If
            GetMenuAll hMenu, mIndex + 1, mMaxCount, strParent
        End If
    End Sub
      

  4.   

    frmMdiMain.hwnd  是指有菜单的那窗体的句柄。
      

  5.   

    xiaoxinghappy(小星) 

    Set nodeX = TVPopedom.Nodes.Add(, , strCaption, strCaption)
    设置的节点的key 和 text 都是菜单的Caption,
    如何得到菜单的name  , 把nodes 的 key 设置为菜单的 name ????