首先做一个菜单,让他不可见,如: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
然后加这些代码:
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
解决方案 »
- 关于窗体关闭时,如何判断text、combo、check空间被编辑过了?
- VB中最多可以包含多少个类模块?
- 大哥们,水晶报表9可否自定义纸张大小?
- 各位这里有没有懂会计的?
- 真心求购比较稳定的个人主页
- [初级]VB中浮点数与字符串的连接问题
- access+vb,数据库表中有作业人员、作业时间(yyyy-mm-dd)、所得工时。现在要进行按月度统计,怎么提取?求帮助,大学生自学中啊
- 在VB中怎样使用滚动条
- 急:如何用VB编写组件在WIN2000添加一用户
- 怎样才呢把无用的控件从控见面版里删除
- 数据库中如何加入图片
- 大家好,恭喜发财!怎么把ACCESS数据库中查询到的记录转换成EXCEL文件(用的是ADO查询)
直接把菜单的结构表示在TREEVIEW控件??
请给个源程序好吗??我哈笨的,看不懂呀!!
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
用
Set nodeX = TVPopedom.Nodes.Add(, , strCaption, strCaption)
设置的节点的key 和 text 都是菜单的Caption,
如何得到菜单的name , 把nodes 的 key 设置为菜单的 name ????