CallWindowProc Function

Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Platforms

Description & Usage

CallWindowProc explicitly calls the hook function acting as a window's procedure to process a message. This allows a message for a window to be processed by a window procedure which is not necessarily the one normally called by the window.

Return Value

The function returns the return value generated after processing the message sent.

Visual Basic-Specific Issues

None.

Parameters

lpPrevWndFunc
A pointer to the window procedure function to call explicitly. This is the function which will process the message.
hWnd
A handle to the window to process the message for.
Msg
The message to process.
wParam
Additional information about the message.
lParam
Additional information about the message.

Example

' This code is licensed according to the terms and conditions listed here.

' Have window Form1 play the SystemAsterisk sound whenever it gets
' or loses the focus.  Do this by specifying a new window procedure which
' plays the sound whenever the WM_ACTIVATE message is received.  To
' process all other messages (and do whatever else WM_ACTIVATE should
' do), the procedure then calls the previous window procedure.

' *** Place this code in a module. ***
Const WM_ACTIVATE = &H6  ' identifier of the message
' The following variable is accessible to all code in this example.
Public pOldProc As Long  ' pointer to the previous window function

' Define the new window procedure.
Public Function WindowProc (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Dim retval As Long
  ' If the message is WM_ACTIVATE (we don't care about the parameters),
  ' play the SystemAsterisk sound.
  If uMsg = WM_ACTIVATE Then
    retval = PlaySound("SystemAsterisk", 0, SND_ALIAS Or SND_ASYNC)
  End If
  ' No matter what happened, use the old window procedure to
  ' finish processing the message.
  retval = CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam)
  ' Have this function return whatever the function above returned.
  WindowProc = retval
End Function

' *** Place the following code wherever you wish. ***
Dim retval As Long  ' return value

' Set the new window procedure for Form1, saving a pointer to the old one.
pOldProc = SetWindowLong(Form1.hWnd, GWL_WNDPROC, AddressOf WindowProc)
' Now WindowProc processes Form1's messages, playing the sound
' whenever Form1 is activated or loses activated status.

See Also

DefWindowProc

Category

Window Procedures

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/c/callwindowproc.html