欢迎来到入门教程网!

vb

当前位置:主页 > 软件编程 > vb >

VB实现屏蔽文本框右键菜单的复制、粘贴等功能的方法

来源:本站原创|时间:2020-01-10|栏目:vb|点击:

本文实例讲述了VB屏蔽文本框中的右键菜单、复制、粘贴等功能的实现方法。该功能就是禁止文本框的右键功能,造成点击鼠标右键无效。是非常常见的一类实用功能。

具体的功能模块代码如下:

'==========================================================
'| 模 块 名 | TextBoxDisableAbility
'| 说  明 | 禁止文本框的功能
'==========================================================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_CUT = &H300 '-------------剪切消息
Private Const WM_COPY As Long = &H301 '-------------复制消息
Private Const WM_PASTE As Long = &H302 '-------------粘贴消息
Private Const WM_CLEAR = &H303 '-------------删除消息[右键菜单的删除]
Private Const EM_UNDO = &HC7 '-------------撤销消息
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_CUT, WM_COPY, WM_PASTE, WM_CLEAR, EM_UNDO, 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

本代码的功能屏蔽文本框的右键菜单、复制、粘贴等,在不少的程序中都可以见到这些功能。共享给各位VB爱好者,希望能对大家有所帮助!

上一篇:vbs中获取脚本当前路径的2个方法

栏    目:vb

下一篇:VBS中InStrRev函数的第三个参数(Start)使用注意事项

本文标题:VB实现屏蔽文本框右键菜单的复制、粘贴等功能的方法

本文地址:https://www.xiuzhanwang.com/a1/vb/7219.html

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 脚本教程网 版权所有