Windows消息WM_USER、WM_APP的区别

以下三段描述准确到位,均摘自网络。

 

描述1:

You should use WM_USER when creating a set of messages for a custom control.

You should use WM_APP when you are ... subclassing controls, or need to send messages to your application window that have meaning to the app.

 

描述2:

There is no difference when you send WM_USER+x or WM_APP+x message within your own rigistered class. For example, main app window.

But if you want to send custom message within any system registerd class (BUTTON, EDIT, e.t.c) you should use WM_APP+x, becuase any WM_USER+x can be already used by the system. For example: #define CBEM_SETEXSTYLE (WM_USER + 8)

摘自:http://social.msdn.microsoft.com/Forums/vstudio/en-US/50a1af87-6b55-4628-b69a-d3a302bf56eb/wmuser-vs-wmapp?forum=vcgeneral

 

描述3:

Valid window messages break down into four categories.

 

    0 .. 0x3FF (WM_USER-1): System-defined messages.

    The meanings of these messages are defined by the operating system and cannot be changed. Do not invent new messages here. Since the meanings are defined by Windows, the operating system understands how to parse the WPARAM and LPARAM parameters and can marshal the messages between processes (or knows to refuse to do so).

 

    0x400 .. 0x7FFF (WM_USER .. WM_APP-1): Class-defined messages.

    The meanings of these messages is determined by the implementor of the window class. (Informally: By the person who calls RegisterClass for that window class.) For example, the WM_USER+1 message means TB_ENABLEBUTTON if the window is a toolbar control, but it means TTM_ACTIVATE if it is a tooltip control, and it means DM_SETDEFID if it is a dialog box. If you created your own control, it would mean something else completely different. Since anybody can create a message in this range, the operating system does not know what the parameters mean and cannot perform automatic marshalling.

 

    0x8000 .. 0xBFFF (WM_APP ... MAXINTATOM-1): Application-defined messages.

    The meanings of these messages is determined by the application that created the window. (Informally: By the person who calls CreateWindow.) This message region was created in Windows 95 to ensure that applications which subclass a window and generate custom messages will not interfere with new messages created by the window class in future versions. Again, since anybody can create a message in this range, the operating system does not know what the parameters mean and cannot perform automatic marshalling.

 

    0xC000 .. 0xFFFF (MAXINTATOM .. MAXWORD): Registered messages.

    The meanings of these messages is determined by the caller of RegisterWindowMessage. Note that the numerical value of registered messages can change from run to run, so you must use RegisterWindowMessage to obtain the message number. Once again, since anybody can create a message in this range, the operating system does not know what the parameters mean and cannot perform automatic marshalling.

摘自:http://blogs.msdn.com/b/oldnewthing/archive/2003/12/02/55914.aspx

原文地址:https://www.cnblogs.com/ant-wjf/p/3384508.html