WNDPROC
The WNDPROC type is a function pointer that represents the window procedure (or callback function) for a window. When the system needs to inform a window about an event (such as a mouse click, key press, or system event), it sends a message to the window. The window procedure receives these messages and processes them accordingly.
Every window in a Windows application has an associated window procedure. This procedure is responsible for handling all messages sent to the window, including creation, destruction, painting, input, and control messages.
Syntax
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Parameters
-
HWND hwnd: A handle to the window. This is the handle of the window that is receiving the message. -
UINT uMsg: The message to be processed. This parameter specifies the type of message that has been sent to the window. For a list of common messages, see Window Messages. -
WPARAM wParam: Additional message information. The exact meaning of this parameter depends on the value of theuMsgparameter. -
LPARAM lParam: Additional message information. The exact meaning of this parameter depends on the value of theuMsgparameter.
Return Value
The return value is the result of the message processing. The exact meaning depends on the message that was sent.
If the application processes the message, it should return a suitable value. If the application does not process the message, it should call the DefWindowProc function to process the message using the default window procedure. For most messages, the return value from DefWindowProc is zero.
Remarks
The window procedure is defined by the application and must conform to the WNDPROC function prototype. The CALLBACK calling convention is used for window procedures.
When creating a window using functions like CreateWindowEx, the window procedure is specified in the lpfnWndProc member of the WNDCLASS or WNDCLASSEX structure.
It is crucial to properly handle all messages, especially WM_DESTROY, which should typically call PostQuitMessage to terminate the application.