In order to allow any window the ability to process any message class, Presentation Manager defines a standard format for messages. In the Presentation Manager environment, a message is composed of four distinct attributes:
All Presentation Manager applications must contain a message processing loop, which receives the message from Presentation Manager (see Application Structure), and routes it, using Presentation Manager message-dispatching functions, to the appropriate window procedure for processing. Thus Presentation Manager actually invokes the window procedure on the application's behalf.
Message Identifier
The message ID identifies the message class to which each message belongs, and is in fact an integer value which is typically replaced by a symbolic name for ease of use. The symbolic names for all system-defined message classes are defined by Presentation Manager; symbolic names for application-defined (private) message classes must be declared by the application developer in the application's source code. This is typically achieved by declaring an integer constant, the value of which is specified as an offset from the system-defined value WM_USER. For example:
#define WMP_MYMESSAGE WM_USER+6
The use of an offset to a system-defined constant, rather than an absolute numeric value, eliminates the chance of using the same integer value as a system-defined message class (with consequently unpredictable results), and avoids the necessity to alter application code should the number or definition of system-defined message classes be altered in future versions of Presentation Manager.
Message Parameters
As noted above, message parameters may contain a variety of information. When used for communication between window procedures, the window handle of the calling window may be passed to the destination window as one of the message parameters, in order that the destination window procedure may dispatch an acknowledgement or reply message to the calling window. Qualifiers to the message type or small items of data may also be passed; for example, the Presentation Manager-defined WM_COMMAND message class (indicating a menu selection by the user) uses the first message parameter to identify the menu item selected.
When large data structures are required to be passed between window procedures, and the data obviously cannot be contained within the two 32-bit message parameters, the convention is to allocate a memory object for the required data structure using the DosAllocMem() function, and to pass a pointer to that memory object as a parameter to the message. Presentation Manager provides a number of macros to enable various types of data to be placed into and retrieved from message parameters. The insertion and retrieval of data into and from message parameters is described in Creating Message Parameters.