程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB綜合教程 >> VB完成屏蔽文本框右鍵菜單的復制、粘貼等功用的辦法

VB完成屏蔽文本框右鍵菜單的復制、粘貼等功用的辦法

編輯:VB綜合教程

VB完成屏蔽文本框右鍵菜單的復制、粘貼等功用的辦法。本站提示廣大學習愛好者:(VB完成屏蔽文本框右鍵菜單的復制、粘貼等功用的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是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喜好者,希望能對大家有所協助!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved