如何移除TextBox、Comb
(完全测试通过,以下代码全部直接复制,若您懒得复制,没有关系,附件里是您要的全部源代码,程序中,在两个控件里按下鼠标右键,程序便会弹出一个提示框,并且右键菜单会消失)
'由于对您的计算机进行了全局监控,因此在关闭程序时,请务必点击窗体中的 "X" 按钮 ,另外如没有一定的基础,请不要对代码进行修改
'在窗体中添加文本框控件
'吃掉文本框控件的右键菜单
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
MsgBox "是不是...全部
(完全测试通过,以下代码全部直接复制,若您懒得复制,没有关系,附件里是您要的全部源代码,程序中,在两个控件里按下鼠标右键,程序便会弹出一个提示框,并且右键菜单会消失)
'由于对您的计算机进行了全局监控,因此在关闭程序时,请务必点击窗体中的 "X" 按钮 ,另外如没有一定的基础,请不要对代码进行修改
'在窗体中添加文本框控件
'吃掉文本框控件的右键菜单
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
MsgBox "是不是没有看到右键菜单了?"
'这里就换成你自己的弹出菜单的代码
End If
End Sub
'程序的第二部分
'******************************
'以下是吃掉组合框控件右键菜单代码
'在窗体中添加一个组合框控件
' 吃掉Combo1控件的右键菜单
'窗体
Private Sub Form_Load()
Hook Me。
hwnd '开启键盘监控程序
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnHook Me。hwnd '关闭键盘监控程序
End Sub
' 标准模块
Private Declare Function SetWindowLong Lib "user32。
dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32。
dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function FindWindowEx Lib "user32。
dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function CallWindowProc Lib "user32。
dll" 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 Const GWL_WNDPROC As Long = -4
Private Const WM_RBUTTONDOWN As Long = &H204
Private hComBo As Long
Private prevProc As Long
Public Sub Hook(ByVal hwnd As Long) '安装键盘监控程序
hComBo = GetHCombo(hwnd)
prevProc = SetWindowLong(hComBo, GWL_WNDPROC, AddressOf WndProc)
End Sub
Public Sub UnHook(ByVal hwnd As Long) '卸载键盘钩子
If prevProc <> GetWindowLong(hComBo, GWL_WNDPROC) Then
Call SetWindowLong(hComBo, GWL_WNDPROC, prevProc)
End If
End Sub
'处理鼠标右键消息
Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wp As Long, ByVal lp As Long) As Long
Select Case uMsg
Case WM_RBUTTONDOWN
MsgBox " 是不是没有看到右键菜单了?"
'这里就可以添加一个您自己的右键菜单
Case Else
WndProc = CallWindowProc(prevProc, hwnd, uMsg, wp, lp)
Exit Function
End Select
WndProc = True
End Function
'获取combo1组件句柄
Private Function GetHCombo(ByVal hwnd As Long) As Long
Dim Temphwnd As Long
Temphwnd = FindWindowEx(hwnd, 0, "ThunderComboBox", vbNullString)
GetHCombo = FindWindowEx(Temphwnd, 0, "Edit", vbunllstring)
End Function
如果您有其他比较简单的办法,请通知我,谢谢^ ^。
收起