Advertisement
2002ASP Miscellaneous #5036

Disable Paste

Disable paste in a textbox.

AI

KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Quellcode
original-source
Put the following code in a bas module.
MODULE:
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
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
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_PASTE = &H302
Type POINTAPI
 x As Long
 y As Long
End Type
Type Msg
 hwnd As Long
 message As Long
 wParam As Long
 lParam As Long
 time As Long
 pt As POINTAPI
End Type
Dim mlPrevProc As Long
Public Sub Hook(robjTextbox As TextBox)
 mlPrevProc = SetWindowLong(robjTextbox.hwnd, GWL_WNDPROC, AddressOf TextProc)
End Sub
Public Sub UnHook(robjTextbox As TextBox)
 SetWindowLong robjTextbox.hwnd, GWL_WNDPROC, PrevProc
End Sub
Public Function TextProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
 If uMsg = WM_PASTE Then
  uMsg = 0
 End If
 
 TextProc = CallWindowProc(mlPrevProc, hwnd, uMsg, wParam, lParam)
End Function
Put the following code in a form.
Option Explicit
Private Sub Form_Load()
 Hook Text1
End Sub
Private Sub Form_Unload(Cancel As Integer)
 UnHook Text1
End Sub
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine