This paper illustrates the realization of the function of the right key menu, copy and paste in VB screen text box. This function is to prevent the text box right button function, resulting in the right mouse click is invalid. is a very common kind of practical function.
The specific function module code is as follows:
'==========================================================
'| Module Name | Textboxdisableability ' | Description | Disable the function of the text box ' ==========================================================option Explicit Private Declare function SetWindowText Lib "user32" Alias "Setwindowtexta" (ByVal hwnd as Long, ByVal lpstring as String) as Long Private Declare F Unction 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 GETW Indowlonga "(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 '-------------cut message Private const wm_copy as Long = &h301 '-------------Copy message privat E Const wm_paste as Long = &h302 '-------------paste message
Private Const Wm_clear = &h303 '-------------Delete message [Delete of right-click menu] Private const Em_undo = &hc7 '-------------undo message Privat E Const wm_contextmenu = &h7b '-------------Right-click menu 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, msg case Wm_cut, wm_copy, wm_ PASTE, Wm_clear, Em_undo, Wm_contextmenu ' Handle custom events here, preferably for empty case Else ' callback system function processing WndProc = CallWindowProc (prevw Ndproc, hwnd, MSG, WParam, LParam) End Select end Function public Sub disableability (Targettextbox as TextBox) ' program start Si cho With this prevwndproc = GetWindowLong (Targettextbox.hwnd, Gwl_wndproc) SetWindowLong Targettextbox.hwnd, GWL_WNDPROC, Addres
SOf WndProc End Sub
The function of this Code screen text box menu, copy, paste, etc., in a number of programs can see these features. To share with you VB enthusiasts, I hope to help you!