vb6.0里面如何右键单击文本框弹出菜单项 5
2个回答
展开全部
楼上的会先弹出系统菜单再弹出自己的菜单,所以要先屏蔽系统菜单,首先要拦截右键信息,新建一个模块
Option Explicit
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private Const WM_CONTEXTMENU = &H7B '-------------右键菜单
Private prevWndProc As Long
Private Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_CONTEXTMENU
'这里处理自定义的事件,最好为空
Case Else
'回调系统函数处理
WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
End Select
End Function
Public Sub DisableAbility(TargetTextBox As TextBox)
prevWndProc = GetWindowLong(TargetTextBox.hwnd, GWL_WNDPROC)
SetWindowLong TargetTextBox.hwnd, GWL_WNDPROC, AddressOf WndProc
End Sub
然后在你的form窗体里写入
Private Sub Form_Load()
DisableAbility Text1'屏蔽系统右键
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then PopupMenu rrr'假设自己的菜单是rrr,弹出自己的菜单
End Sub
展开全部
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then PopupMenu mnu_mymenu
End Sub
mnu_mymenu 就是使用菜单编辑器设置的 第一层名称(设置在该次层的名称标题都会出现)
第一层名称的“标题”可以随便写,(这个标题设置为隐藏、“可见”选项不要打勾)
If Button = vbRightButton Then PopupMenu mnu_mymenu
End Sub
mnu_mymenu 就是使用菜单编辑器设置的 第一层名称(设置在该次层的名称标题都会出现)
第一层名称的“标题”可以随便写,(这个标题设置为隐藏、“可见”选项不要打勾)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |