' ========================================================== ' | Module Name | Textboxdisableability ' | Description | Disable the function of the text box ' ==========================================================option explicitprivate Declare function SetWindowText Lib "user32" Alias "Setwindowtexta" (ByVal hwnd as Long, ByVal lpstring as String) as Longprivate Declare Fu Nction 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 Longprivate Declare Function getwindowlong Lib "user32" Alias "Getwin Dowlonga "(ByVal hwnd as Long, ByVal NIndex as Long) as Longprivate Declare Function setwindowlong Lib" user32 "Alias" Set Windowlonga "(ByVal hwnd as Long, ByVal NIndex as Long, ByVal Dwnewlong as Long) as longprivate Const Gwl_wndproc = ( -4) Pr ivate Const Wm_cut = &h300 '-------------cut message Private Const wm_copy as Long = &h301 '-------------copy message Private Const Wm_paste as Long = &h302 '-------------paste message private ConsT wm_clear = &h303 '-------------Delete message [the deletion of the right-click menu]private Const Em_undo = &hc7 '-------------revoke the message Private Const Wm_con Textmenu = &h7b '-------------Right-click menu Private prevwndproc as Longprivate 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, E M_undo, Wm_contextmenu ' handles custom events here, preferably empty case Else ' callback system function Handling WndProc = CallWindowProc (Prevwndproc, hwnd, MSG, WPa RAM, LParam) End selectend functionpublic Sub disableability (targettextbox as TextBox) ' Call this prevwndproc when the program starts = Getwind Owlong (Targettextbox.hwnd, Gwl_wndproc) SetWindowLong Targettextbox.hwnd, GWL_WNDPROC, AddressOf WndProcEnd Sub
Reprint-VB Disable the text box right-click menu and other functions