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喜好者,願望能對年夜家有所贊助!