33.1.1 Messages

Windows passes input to a window procedure in the form of messages. Messages are generated by Windows and by applications. Windows generates a message at each input event, such as when the user types, moves the mouse, or clicks a control such as a scroll bar. Windows also generates messages in response to changes in the system brought about by an application, such as when an application changes the pool of system font resources or resizes one of its windows. An application can generate messages to direct its own windows to carry out tasks, or to communicate with windows in other applications.

Windows passes a message to a window procedure as a set of four parameters: a window handle, a message identifier, and two 32-bit values called message parameters. The window handle identifies the window for which the message is intended. Windows uses the handle to determine which window procedure to pass the message to.

A message identifier is a named constant that identifies a message's purpose. When a window procedure receives a message, it uses the message identifier to determine how to process the message. For example, WM_PAINT is a message identifier that tells a window procedure that the window's client area has changed and needs to be repainted.

The message parameters specify data or the location of data that a window procedure uses when processing a message. The meaning and value of the message parameters depend on the message. A message parameter can contain an integer, packed bit flags, a pointer to a structure that contains additional data, and so on. Some messages do not use message parameters and typically set the parameters to NULL. A window procedure must check the message identifier to determine how to interpret the message parameters.