In
Win32
The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. The name Windows API collectively refers to several different platform implementations ...
application programming, WindowProc (or window procedure) is a user-defined
callback function
In computer programming, a callback or callback function is any reference to executable code that is passed as an argument to another piece of code; that code is expected to ''call back'' (execute) the callback function as part of its job. Thi ...
that processes messages sent to a window. This function is specified when an application registers its
window class
In computer programming, a window class is fundamental to the Microsoft Windows (Win16, Win32, and Win64) operating systems and its Application Programming Interface (API).
The structure provides a template from which windows may be created by ...
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
In computer programming, a function prototype or function interface is a declaration of a function that specifies the function’s name and type signature (arity, data types of parameters, and return type), but omits the function body. While a ...
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.
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 whatever messages it has not processed are passed on to the default procedure.
See also
*
Event loop In computer science, the event loop is a programming construct or design pattern that waits for and dispatches events or messages in a program. The event loop works by making a request to some internal or external "event provider" (that generally ...
External links
"Writing the Window Procedure" at Microsoft LearnDefWindowProc at Microsoft Learn
Events (computing)
Microsoft application programming interfaces