Declare Function DefWindowProc Lib "user32.dll" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
DefWindowProc explicitly calls the operating system's default window procedure to process a message for a window. This default window procedure provides the minimal functionality necessary for a window procedure function and should be used to provide the default implementation of window messages.
The function returns the return value of whatever message was processed.
None.
' This code is licensed according to the terms and conditions listed here.
' Demonstrate how Visual Basic provides a more robust window
' procedure for windows it creates for the programmer when compared
' to Windows's default window procedure. Do this by "toggling" between
' the default and the Visual Basic provided one.
' *** Place the following code in a module. ***
Public pVBProc As Long ' pointer to Visual Basic's window procedure
' (The above variable defaults to 0 automatically.)
' The following function acts as a wrapper. All it
' does is call the default window procedure.
Public Function WindowProc (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' Call the default window procedure and return its result.
WindowProc = DefWindowProc(hWnd, uMsg, wParam, lParam)
End Function
' *** Place the following code wherever you wish. ***
Dim retval As Long ' return value
If pVBProc = 0 Then
' Window Form1 is using the VB-provided procedure. Switch to using
' the default one and save the pointer to the VB one.
pVBProc = SetWindowLong(Form1.hWnd, GWL_WNDPROC, AddressOf WindowProc)
Else
' Window Form1 is using the default procedure (via the wrapper
' function). Switch to using the VB one.
retval = SetWindowLong(Form1.hWnd, GWL_WNDPROC, pVBProc)
' Set pVBProc to 0 so we know which one is being used.
pVBProc = 0
End If
' By allowing the user to switch back and forth, the differences will
' become apparent.
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: August 23, 1999
This page is copyright © 1999 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/d/defwindowproc.html