DefWindowProc
The DefWindowProc
function calls the default window procedure to provide default processing for any window messages that an application does not process. This function ensures standard behavior for windows that your program creates.
Syntax
LRESULT DefWindowProc(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
Parameters
Parameter | Type | Description |
---|---|---|
hWnd | HWND | Handle to the window receiving the message. |
Msg | UINT | Message identifier. |
wParam | WPARAM | Additional message information. The content of this parameter depends on the value of Msg . |
lParam | LPARAM | Additional message information. The content of this parameter depends on the value of Msg . |
Return Value
The return value is a LRESULT
that indicates the result of message processing. Its meaning depends on the message specified by Msg
.
Remarks
- Every window procedure should call
DefWindowProc
for any messages it does not explicitly handle. - If you process a message and do not call
DefWindowProc
, you must ensure you return an appropriate value for that message. - Commonly used messages that require default processing include
WM_NCCREATE
,WM_NCHITTEST
, andWM_GETMINMAXINFO
. - The function is exported from
User32.dll
.
Example
#include <windows.h>
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
// Initialization code here
return 0;
case WM_PAINT:
// Paint handling here
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
// Let the default window procedure handle everything else
return DefWindowProc(hWnd, message, wParam, lParam);
}
}