Option ExplicitPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) '---加下面2句话 Text1.Enabled = False Text1.Enabled = True If Button = 2 Then PopupMenu MnuA End If End Sub
'窗体代码 Option ExplicitPrivate Sub Command1_Click() prevWndProc = GetWindowLong(Text1.hWnd, GWL_WNDPROC) SetWindowLong Text1.hWnd, GWL_WNDPROC, AddressOf WndProc Command1.Enabled = False Text1 = "单击第一个命令按钮后,如果单击鼠标右键则不再弹出菜单" End SubPrivate Sub Command2_Click() Unload Me End SubPrivate Sub Form_Load() Text1 = "在文本框内单击鼠标右键可弹出菜单" End SubPrivate Sub Form_Unload(Cancel As Integer) If prevWndProc <> 0 Then SetWindowLong Text1.hWnd, GWL_WNDPROC, prevWndProc prevWndProc = 0 End If End Sub'模块代码 Option ExplicitPublic Const GWL_WNDPROC = (-4) Public Const WM_RBUTTONDOWN = &H204Public 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 Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPublic prevWndProc As LongFunction WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If Msg = WM_RBUTTONDOWN Then '不执行任何操作 Else WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam) End If End Function
'---加下面2句话
Text1.Enabled = False
Text1.Enabled = True If Button = 2 Then PopupMenu MnuA End If
End Sub
Option ExplicitPrivate Sub Command1_Click()
prevWndProc = GetWindowLong(Text1.hWnd, GWL_WNDPROC)
SetWindowLong Text1.hWnd, GWL_WNDPROC, AddressOf WndProc
Command1.Enabled = False
Text1 = "单击第一个命令按钮后,如果单击鼠标右键则不再弹出菜单"
End SubPrivate Sub Command2_Click()
Unload Me
End SubPrivate Sub Form_Load()
Text1 = "在文本框内单击鼠标右键可弹出菜单"
End SubPrivate Sub Form_Unload(Cancel As Integer)
If prevWndProc <> 0 Then
SetWindowLong Text1.hWnd, GWL_WNDPROC, prevWndProc
prevWndProc = 0
End If
End Sub'模块代码
Option ExplicitPublic Const GWL_WNDPROC = (-4)
Public Const WM_RBUTTONDOWN = &H204Public 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
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPublic prevWndProc As LongFunction WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_RBUTTONDOWN Then
'不执行任何操作
Else
WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam)
End If
End Function