怎样在vb中使用popupmenu,将多个菜单显示到同一个右键菜单,比如我想将菜单栏的多个菜单:file,edit等

多个根菜单的子菜单都显示到右键弹出菜单,怎么做呢,难道要重新将这个子菜单组合到一个新的菜单中... 多个根菜单的子菜单都显示到右键弹出菜单,怎么做呢,难道要重新将这个子菜单组合到一个新的菜单中 展开
 我来答
zgwxm
2011-10-23 · 经典歌曲、名人名家歌曲视频
zgwxm
采纳数:1792 获赞数:21142

向TA提问 私信TA
展开全部
'我这里有一个以前在网上找的代码,没有加以研究,你看看是否对你有用。
'把下面代码保存为Form1.frm,然后打开文件,运行后在窗体空白处按鼠标右键,即可看到你想看到的效果。
'====Form1.frm====
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 165
ClientTop = 855
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.Label Label1
Caption = "请在窗体内按鼠标右键,会弹出重组后的菜单。"
Height = 375
Left = 120
TabIndex = 0
Top = 120
Width = 4455
End
Begin VB.Menu m1
Caption = "AAA"
Begin VB.Menu m11
Caption = "aaa"
End
Begin VB.Menu m12
Caption = "bbb"
End
Begin VB.Menu m13
Caption = "ccc"
End
End
Begin VB.Menu m2
Caption = "BBB"
Begin VB.Menu m21
Caption = "ddd"
End
Begin VB.Menu m22
Caption = "eee"
End
Begin VB.Menu m23
Caption = "fff"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const MF_CHECKED = &H8&
Const MF_APPEND = &H100&
Const TPM_LEFTALIGN = &H0&
Const MF_DISABLED = &H2&
Const MF_GRAYED = &H1&
Const MF_SEPARATOR = &H800&
Const MF_STRING = &H0&
Const TPM_RETURNCMD = &H100&
Const TPM_RIGHTBUTTON = &H2&
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function CreatePopupMenu Lib "user32" () As Long
Private Declare Function TrackPopupMenuEx Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal HWnd As Long, ByVal lptpm As Any) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim hMenu As Long
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then
Dim Pt As POINTAPI
Dim ret As Long
hMenu = CreatePopupMenu()
AppendMenu hMenu, MF_STRING, 1, m13.Caption
AppendMenu hMenu, MF_STRING, 2, m22.Caption
GetCursorPos Pt
ret = TrackPopupMenuEx(hMenu, TPM_LEFTALIGN Or TPM_RETURNCMD Or TPM_RIGHTBUTTON, Pt.x, Pt.y, Me.HWnd, ByVal 0&)
DestroyMenu hMenu
Select Case ret
Case 1
MsgBox m13.Caption
Case 2
MsgBox m22.Caption
End Select
End If
End Sub
yangyingjun999
2011-10-23 · TA获得超过1230个赞
知道小有建树答主
回答量:782
采纳率:0%
帮助的人:413万
展开全部
这种想法应该是不行吧,看来还只有“重新将这个子菜单组合到一个新的菜单中”,这样虽然麻烦点、但至少可以在重组中从新排列格式并做筛选。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
excel实用文档
2011-10-23 · 各行各业有用的EXCEL模板
excel实用文档
采纳数:71 获赞数:18810

向TA提问 私信TA
展开全部
这个真麻烦
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式