HOWTO: Define Private Messages for Application Use

ID: Q86835


The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) 3.1
  • Microsoft Win32 Software Development Kit (SDK)
  • Microsoft Windows 2000


SUMMARY

In the Microsoft Windows environment, an application can define a private message for its own use without calling the RegisterWindowMessage API. Message numbers between 0x8000 and 0xBFFF are reserved for this purpose.

For Windows NT and Windows 95, the system defines a new message WM_APP (value 0x8000). Applications can make use of the range WM_APP through 0xBFFF for private messages without conflict. The only requirement is that the .EXE file must be marked version 4.0 (use the linker switch /subsystem:windows,4.0). Windows NT 3.5 and 3.51 and Windows 95 will run applications marked version 4.0.


MORE INFORMATION

The WM_APP constant is used by applications to help define private message, usually of the from WM_APP + X, where X is an integer value.
WM_APP is defined in winuser.h as


#if(WINVER >= 0x0400)
#define WM_APP                          0x8000
#endif /* WINVER >= 0x0400 */  
The documentation for the WM_USER message lists four ranges of message numbers as follows:

   Message Number           Description
   --------------------------------------------------------------------

   0 through WM_USER-1      Messages reserved for use by Windows.

   WM_USER through 0x7FFF   Integer messages for use by private window
                            classes.

   WM_APP through 0xBFFF    Messages available for use by applications.

   0xC000 through 0xFFFF    String messages for use by applications.

   Greater than 0xFFFF      Reserved by Windows for future use. 
When an application subclasses a predefined Windows control or provides a special message in its dialog box procedure, it cannot use a WM_USER+x message to define a new message because the predefined controls use some WM_USER+x messages internally. It was necessary to use the RegisterWindowMessage function to retrieve a unique message number between 0xC000 and 0xFFFF.

To avoid this inconvenience, messages between 0x8000 and 0xBFFF were redefined to make them available to an application. Messages in this range do not conflict with any other messages in the system.

The distinction here is that WM_USER messages are specific to a window class (whether it is a control or a user-defined class), while WM_APP messages are not. While WM_USER messages can be treated as application messages, the danger in doing so is that if any are already pre-defined for a particular window class, they could be misinterpreted upon receipt.

Additional query words:

Keywords : kbNTOS kbGrpUser kbWinOS kbWndw kbWndwMsg
Version : WINDOWS:3.1
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: February 3, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.