What does the message mean?
Message system is very important for a Win32 program, it is a power source of program running. A message is a system-defined 32-bit value that uniquely defines an event and sends a notification to Windows telling the application that something has happened. For example, clicking a mouse, changing the window size, and pressing a key on the keyboard will cause Windows to send a message to the application.
The message itself is passed as a record to the application, which contains the type of message and other information. For example, for a message that is generated by a mouse click, the record contains the coordinates of the mouse click. This record type, called MSG,MSG, contains message information from a Windows Application message queue, which is declared in Windows as follows:
typedef struct tagMsg
{
HWND hwnd; 接受该消息的窗口句柄
UINT message; 消息常量标识符,也就是我们通常所说的消息号
WPARAM wParam; 32位消息的特定附加信息,确切含义依赖于消息值
LPARAM lParam; 32位消息的特定附加信息,确切含义依赖于消息值
DWORD time; 消息创建时的时间
POINT pt; 消息创建时的鼠标/光标在屏幕坐标系中的位置
}MSG;
Messages can be generated by a system or application. The system generates a message when an input event occurs. For example, when the user keystrokes, move the mouse or click the control. The system also generates messages to respond to changes brought about by the application, such as changing the system font to change the size of the form. An application can generate messages to enable a form to perform tasks, or to communicate with a window in another application.
What's in the message?
We have given the above annotation, will not have a clearer understanding of the message structure? If not, then we will try to give the following explanation:
The HWND 32-bit window handle. A window can be any type of screen object, because Win32 can maintain the handles of most visual objects (Windows, dialog boxes, buttons, edit boxes, and so on).
The message is used to distinguish constant values from other messages, which can be predefined constants in Windows cells or custom constants. The message identifier indicates the meaning of the message in a constant-named manner. When a window procedure receives a message, he uses the message identifier to decide how to process the message. For example, Wm_paint tells the window that the client area of the process form is changed and needs to be redrawn. A symbolic constant specifies the category in which the system message belongs, and its prefix indicates the type of form that handles the interpreted message.
WParam is usually a constant value that is related to a message, or it may be a handle to a window or control.
LParam is usually a pointer to data in memory. Because wparam, lparam, and pointer are both 32-bit, they can be converted to each other.
The value of the message identifier
The system retains the value of the message identifier in the range of 0x0000 in 0x03ff (wm_user-1). These values are used by system-defined messages. Applications cannot use these values to their own messages. Application messages are used by the application itself from Wm_user (0x0400) to 0x7FFF, or from 0xc000 to 0xffff;wm_user-range messages, and 0x7fff to 0XFFFF-wide messages to communicate with other applications. By the way, we have an iconic message value:
Wm_null---0x0000 empty message.
0x0001----0x0087 is mainly a window message.
0X00A0----0X00A9 Non-client zone messages
0x0100----0X0108 Keyboard message
0x0111----0x0126 Menu Message
0x0132----0x0138 Color Control Message
0x0200----0X020A Mouse message
0x0211----0x0213 Menu Loop message
0X0220----0x0230 Multiple document messages
0X03E0----0X03E8 DDE Message
0x0400 Wm_user
0x8000 Wm_app
0x0400----0X7FFF Application custom Private messages