如何去掉textbox控件的右击快捷菜单?

解决方案 »

  1.   

    有个简单的想法,你可以试试.
    就是在TEXT的MOUSEDOWN事件中使用SENDKEYS发送按键"ESC"
      

  2.   

    3.屏蔽textbox控件自身的右键菜单,并显示自己的菜单。
    方法一:
    Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y _
    As Single)
       If Button = 2 Then
         Text1.Enabled = False
         Text1.Enabled = True
         PopupMenu mymenu
       End If
    End Sub方法二:回调函数
    module:
    Option Explicit
    Public OldWindowProc As Long ' 保存默认的窗口函数的地址
    Public Const WM_CONTEXTMENU = &H7B ' 当右击文本框时,产生这条消息
    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 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
    Public Function SubClass_WndMessage(ByVal hWnd As Long, ByVal Msg As Long, ByVal wp _
     As Long, ByVal lp As Long) As Long
    ' 如果消息不是WM_CONTEXTMENU,就调用默认的窗口函数处理
     If Msg <> WM_CONTEXTMENU Then
       SubClass_WndMessage = CallWindowProc(OldWindowProc, hWnd, Msg, wp, lp)
       Exit Function
     End If
     SubClass_WndMessage = True
    End Function
    窗体中:
    Private Const GWL_WNDPROC = (-4)
    Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y _ 
    As Single)
     If Button = 1 Then Exit Sub
       OldWindowProc = GetWindowLong(Text1.hWnd, GWL_WNDPROC) ' 取得窗口函数的地址
          ' 用SubClass_WndMessage代替窗口函数处理消息
       Call SetWindowLong(Text1.hWnd, GWL_WNDPROC, AddressOf SubClass_WndMessage)
    End Sub
    Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
      If Button = 1 Then Exit Sub
        ' 恢复窗口的默认函数
        Call SetWindowLong(Text1.hWnd, GWL_WNDPROC, OldWindowProc)
        PopupMenu mymenu
    End Sub