33.1.5 Message Types

This section describes the two types of Windows messages: system-defined messages and application-defined messages.

33.1.5.1 System-Defined Messages

There are many system-defined messages. The system uses these messages to control the operations of applications and to provide input and other information for applications to process. The system sends or posts a system-defined message when it communicates with an application. An application can also send or post system-defined messages. Applications typically use these messages to control the operation of control windows created by using preregistered window classes.

Each system message has a unique message identifier and a corresponding symbolic constant. The symbolic constant, defined in the Windows header files, typically states the purpose of the message. For example, the WM_PAINT constant represents the paint message. The paint message requests that a window paint its contents.

The symbolic constants also specify the message category. System-defined messages can belong to several categories; the prefix identifies the type of window that can interpret and process the messages. The following list gives the prefixes and related message categories:

Prefix Message category

BM Button control
CB Combo-box control
DM Default pushbutton control
EM Entryfield control
LB Listbox control
WM General window

General window messages cover a wide range of information and requests and include mouse and keyboard-input messages, menu and dialog-input messages, window-creation and window-management messages, and dynamic-data-exchange (DDE) messages.

33.1.5.2 Application-Defined Messages

An application can create its own messages to use in its own windows or to communicate with windows in other processes. If an application does create messages, the window procedure that receives them must interpret the messages and provide appropriate processing.

Windows reserves the message-identifier values in the range 0x0000 through 0x03FF (the value of WM_USER – 1) and 0x8000 through 0xBFFF for system-defined messages. Applications cannot use these values for private messages.

Values in the range 0x0400 (the value of WM_USER) through 0x7FFF are available for message identifiers defined by an application for use in that application. Values in the range 0xC000 through 0xFFFF are available for message identifiers defined by an application for use in communicating with windows in other applications.

Windows returns a message identifier in the range 0xC000 through 0xFFFF when an application calls the RegisterWindowMessage function to register a message. The message identifier returned by RegisterWindowMessage is guaranteed to be unique throughout the system. If your application creates messages that it uses to communicate with windows in other applications, it should use RegisterWindowMessage to register the message. This avoids conflicts that could arise if other applications used the same message identifier but for a different purpose. For more information about the system atom table, see Chapter 21, “Atoms.”