10 out of 12 rated this helpful - Rate this topic

CallWindowProc function

Applies to: desktop apps only

Passes message information to the specified window procedure.

Syntax

LRESULT WINAPI CallWindowProc(
  __in  WNDPROC lpPrevWndFunc,
  __in  HWND hWnd,
  __in  UINT Msg,
  __in  WPARAM wParam,
  __in  LPARAM lParam
);

Parameters

lpPrevWndFunc [in]

Type: WNDPROC

The previous window procedure. If this value is obtained by calling the GetWindowLong function with the nIndex parameter set to GWL_WNDPROC or DWL_DLGPROC, it is actually either the address of a window or dialog box procedure, or a special internal value meaningful only to CallWindowProc.

hWnd [in]

Type: HWND

A handle to the window procedure to receive the message.

Msg [in]

Type: UINT

The message.

wParam [in]

Type: WPARAM

Additional message-specific information. The contents of this parameter depend on the value of the Msg parameter.

lParam [in]

Type: LPARAM

Additional message-specific information. The contents of this parameter depend on the value of the Msg parameter.

Return value

Type:

Type: LRESULT

The return value specifies the result of the message processing and depends on the message sent.

Remarks

Use the CallWindowProc function for window subclassing. Usually, all windows with the same class share one window procedure. A subclass is a window or set of windows with the same class whose messages are intercepted and processed by another window procedure (or procedures) before being passed to the window procedure of the class.

The SetWindowLong function creates the subclass by changing the window procedure associated with a particular window, causing the system to call the new window procedure instead of the previous one. An application must pass any messages not processed by the new window procedure to the previous window procedure by calling CallWindowProc. This allows the application to create a chain of window procedures.

If STRICT is defined, the lpPrevWndFunc parameter has the data type WNDPROC. The WNDPROC type is declared as follows:

LRESULT (CALLBACK* WNDPROC) (HWND, UINT, WPARAM, LPARAM); 

If STRICT is not defined, the lpPrevWndFunc parameter has the data type FARPROC. The FARPROC type is declared as follows:

int (FAR WINAPI * FARPROC) () 

In C, the FARPROC declaration indicates a callback function that has an unspecified parameter list. In C++, however, the empty parameter list in the declaration indicates that a function has no parameters. This subtle distinction can break careless code. Following is one way to handle this situation:

#ifdef STRICT 
  WNDPROC MyWindowProcedure 
#else 
  FARPROC MyWindowProcedure 
#endif 
... 
  lResult = CallWindowProc(MyWindowProcedure, ...) ; 

For further information about functions declared with empty argument lists, refer to The C++ Programming Language, Second Edition, by Bjarne Stroustrup.

The CallWindowProc function handles Unicode-to-ANSI conversion. You cannot take advantage of this conversion if you call the window procedure directly.

Examples

For an example, see Subclassing a Window

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

Unicode and ANSI names

CallWindowProcW (Unicode) and CallWindowProcA (ANSI)

See also

Reference
GetWindowLong
SetClassLong
SetWindowLong
Conceptual
Window Procedures

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
vb.net syntax
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function CallWindowProc(ByVal wndProc As IntPtr, ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr End Function
C# syntax
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);