# WindowProc

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/WindowProc
> Markdown URL: https://mediated.wiki/source/WindowProc.md
> Source: https://en.wikipedia.org/wiki/WindowProc
> Source revision: 1281076301
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

In [Win32](/source/Win32) application programming, **WindowProc** (or **window procedure**), also known as **WndProc** is a user-defined [callback function](/source/Callback_(computer_science)) that processes messages sent to a window. This function is specified when an application registers its [window class](/source/Window_class) and can be named anything (not necessarily **WindowProc**).

## Message handling

The window procedure is responsible for handling all messages that are sent to a window. The [function prototype](/source/Function_prototype) of WindowProc is given by:

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

hwnd is a handle to the window to which the message was sent and uMsg identifies the actual message by its identifier, as specified in [winuser.h](/source/Windows_USER).

wParam and lParam are parameters whose meaning depends on the message. An application should identify the message and take the required action.

## Default processing

Hundreds of different messages are produced as a result of various events taking place in the system, and typically, an application processes only a small fraction of these messages. In order to ensure that all messages are processed, Windows provides a default window procedure called **DefWindowProc** that provides default processing for messages that the application itself does not process.

An application usually calls **DefWindowProc** at the end of its own **WindowProc** function, so that unprocessed messages can be passed down to the default procedure.

## See also

- [Event loop](/source/Event_loop)

- [Desktop Window Manager](/source/Desktop_Window_Manager)

## External links

- ["Writing the Window Procedure" at Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/learnwin32/writing-the-window-procedure)

- [DefWindowProc at Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-defwindowprocw)

---
Adapted from the Wikipedia article [WindowProc](https://en.wikipedia.org/wiki/WindowProc) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/WindowProc?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
