I was wondering if anybody has any samples on how to use the WindowsProc API.
Many thanks,
Desire
Printable View
I was wondering if anybody has any samples on how to use the WindowsProc API.
Many thanks,
Desire
Here's a quick example which disables the ability to Paste within a Textbox:
Code:'In a Module..
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private 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
Private Const GWL_WNDPROC = (-4)
Private Const WM_PASTE = &H302
Private lPrevWndFunc As Long
Private Function WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg <> WM_PASTE Then
'Prevent the Paste Message from Being Processed by the Textbox
WindowProc = CallWindowProc(lPrevWndFunc, hWnd, Msg, wParam, lParam)
End If
End Function
Public Sub SubClassWnd(ByVal hWnd As Long)
'Start Subclassing the Specified Window
lPrevWndFunc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub EndSubClass(ByVal hWnd As Long)
'End Subclassing of the Specified Window
Call SetWindowLong(hWnd, GWL_WNDPROC, lPrevWndFunc)
End Sub
------------------Code:'In a Form with a Textbox..
Private Sub Form_Load()
'Subclass the Textbox
SubClassWnd Text1.hWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Remove the Subclassing on the Textbox
'MUST be done, do NOT close the App using the End Button
'Close the Form Normally First, or VB WILL CRASH!!
EndSubClass Text1.hWnd
End Sub
Aaron Young
Analyst Programmer
[email protected]
[email protected]