答案:1. 问题出在这里:
iAns = TrackPopupMenu(hMenu, TPM_RETURNCMD, X, Y, 0, hwnd, rct) '显示弹出式菜单并返回选取条目命令ID(这里是1-6)
hwnd 必须是listbox的句柄。这里没有正确的初始化。
2. 解决方法:
在module中加声明:
Public Const MF_ENABLED = &H0&
Public Const TPM_RETURNCMD = &H100&
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
在userform中修改。
Sub ShowPopMenu_Txt(ByVal x As Single, ByVal y As Single)
Dim rct As RECT
Dim hMenu As Long, lOption As Long
Dim iAns As Integer
hMenu = CreatePopupMenu() '
AppendMenu hMenu, MF_ENABLED, 1, "删除项" '增加菜单条目
AppendMenu hMenu, MF_ENABLED, 2, "清空列表" '增加菜单条目
hwnd = FindWindow("ThunderDFrame", "UserForm1")
iAns = TrackPopupMenu(hMenu, TPM_RETURNCMD, X, Y, 0, hwnd, rct) '显示弹出式菜单并返回选取条目命令ID(这里是1-6)
Call PopMenuAction_Lis(ByVal iAns) '执行条目代码
DestroyMenu hMenu '销毁弹出菜单
End Sub
上一个:vb小白询问一个问题
下一个:vb怎么用打印机打印已有文档(如D盘中的某个word文档)