VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Disable Paste

by Johan (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (8 Votes)

Disable paste in a textbox.

API Declarations
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

Rate Disable Paste

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

Download this snippet    Add to My Saved Code

Disable Paste Comments

No comments have been posted about Disable Paste. Why not be the first to post a comment about Disable Paste.

Post your comment

Subject:
Message:
0/1000 characters