ianpaisley
Oct 30th, 1999, 05:59 PM
Hi,
I've discovered a snippet of code that will enable me to prevent people cutting, copying and pasting text from my textbox. It works fine with a text box, but I can't figure out how to work it if I have an array of boxes. I keep getting a runtime error 13 - Type mismatch.
I'd be grateful if you could help me out because I've tried lots of ways, and just can't do it.
It involves a module, a form and a textbox (text1). In the module:
Option Explicit
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 Const GWL_WNDPROC = (-4)
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_CUT = &H300
Public Const WM_COPY = &H301
Public Const WM_PASTE = &H302
Public lpPrevWndFunc As Long
Sub Hook(ctlthis As Control)
lpPrevWndFunc = SetWindowLong(ctlthis.hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Sub UnHook(ctlthis As Control)
Call SetWindowLong(ctlthis.hwnd, GWL_WNDPROC, lpPrevWndFunc)
End Sub
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_RBUTTONDOWN, WM_CUT, WM_COPY, WM_PASTE
WndProc = 0
Case Else
WndProc = CallWindowProc(lpPrevWndFunc, hwnd, Msg, wParam, lParam)
End Select
End Function
And in the form:
Private Sub Form_Load()
Call Hook(Text1)
End Sub
Now it works fine if I just have one Text1. But the way my program will be, I have to have four text1s, a control array.
Whenever I run my program I get that runtime error - type mismatch, and in the form load 'Call Hook(Text1)' turns out in yellow.
I've tried Call Hook(text1(index)) and lots of others, but had no luck.
Thanks for any help!
I've discovered a snippet of code that will enable me to prevent people cutting, copying and pasting text from my textbox. It works fine with a text box, but I can't figure out how to work it if I have an array of boxes. I keep getting a runtime error 13 - Type mismatch.
I'd be grateful if you could help me out because I've tried lots of ways, and just can't do it.
It involves a module, a form and a textbox (text1). In the module:
Option Explicit
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 Const GWL_WNDPROC = (-4)
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_CUT = &H300
Public Const WM_COPY = &H301
Public Const WM_PASTE = &H302
Public lpPrevWndFunc As Long
Sub Hook(ctlthis As Control)
lpPrevWndFunc = SetWindowLong(ctlthis.hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Sub UnHook(ctlthis As Control)
Call SetWindowLong(ctlthis.hwnd, GWL_WNDPROC, lpPrevWndFunc)
End Sub
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_RBUTTONDOWN, WM_CUT, WM_COPY, WM_PASTE
WndProc = 0
Case Else
WndProc = CallWindowProc(lpPrevWndFunc, hwnd, Msg, wParam, lParam)
End Select
End Function
And in the form:
Private Sub Form_Load()
Call Hook(Text1)
End Sub
Now it works fine if I just have one Text1. But the way my program will be, I have to have four text1s, a control array.
Whenever I run my program I get that runtime error - type mismatch, and in the form load 'Call Hook(Text1)' turns out in yellow.
I've tried Call Hook(text1(index)) and lots of others, but had no luck.
Thanks for any help!