Message Mechanism in VC (1) (Transfer from PCVC Forum)

zhaozj2021-02-16  73

What is the message? The message system is very important for a Win32 program, it is a power source of a program run. A message is a 32-bit value defined by the system. He is the only event that issues a notification to Windows, telling an app to happen. For example, click the mouse, change the window size, press a key on the keyboard to send Windows to your application.

The message itself is passed to the application as a record, and this record contains the type of message and other information. For example, for messages generated by clicking on the mouse, this record contains the coordinates when clicking the mouse. This record type is called MSG, and the MSG contains message information from the Windows application message queue. It declares in Windows as follows:

Typedef struct tagmsg

{

HWND hWnd; Accept the window handle

UINT Message; Message constant identifier, that is, what we usually say

WPARAM WPARAM; specific additional information for 32-bit messages, exact meaning depends on message values

LPARAM LPARAM; 32-bit messages specific additional information, exact meaning depends on message values

DWORD TIME; time when the message is created

Point PT; Mouse / cursor in the screen in the screen coordinate

} Msg;

The message can be generated by a system or application. The system generates a message when an input event occurs. For example, when the user knocks the key, move the mouse or click the control. The system also generates a message to respond to changes by the application, such as the application changing the system font to change the form size. Applications can generate messages to make the form perform tasks or communicate with windows in other applications.

What is there in the news? We give the above note, is it a clearer understanding of the message structure? If there is not yet, then we try to give the following explanation: HWND 32-bit window handle. The window can be any type of screen object because Win32 is able to maintain the handle of most visual objects (windows, dialogs, buttons, edit boxes, etc.). Message is used to distinguish constant values ​​for other messages, which may be predefined in the Windows unit, or they can be custom constants. The message identifier indicates the meaning of the message in a constant mode. When the window procedure receives the message, he will use the message identifier to determine how to handle the message. For example, WM_Paint tells the window Process Form Customer Area to be changed. Symbol constant Specifies the category belonging to the system message, which indicates the type of the form that handles the form of the message. WPARAM is usually a constant value related to messages or a handle of a window or control. LPARAM is usually a pointer to data in memory. Because WPARAM, LPARAM and POIIters are 32-bit, they can be converted between them.

The value system of the message identifier retains the value of the message identifier at 0x0000 in the range of 0x03FF (WM_USER-1). These values ​​are used by the system definition message. Applications cannot use these values ​​to give their own messages. Application messages from WM_USER (0x0400) to 0x7FFF, or 0xc000 to 0xfff; WM_USER to 0x7FFF range message by the application yourself; 0xC000 to 0xffffffffffffffff-range messages are used to communicate with other applications, we are in place with iconic Message Value: WM_NULL --- 0x0000 Air message. 0x0001 ---- 0x0087 is mainly a window message. 0x00A0 ---- 0x00A9 Non-Customer Message 0x0100 ---- 0x0108 Keyboard Message 0x0111 ---- 0x0126 Menu Message 0x0132 ---- 0x0138 Color Control Message 0x0200 ---- 0x020A Mouse Message 0x0211 ---- 0x0213 Menu Cycle message 0x0220 ---- 0x0230 multi-document message 0x03E0 ---- 0x03E8 DDE message 0x0400 WM_USER 0X8000 WM_APP 0x0400 ---- 0x7FFF application Custom private message message What are the text messages? In fact, there are many news in Windows, but the type is not complicated, and there are 3 types: window messages, command messages, and control notification messages. Window messages are probably the most common message in the system, which refers to the messages used by the operating system and the window that controls other windows. For example, CREATEWINDOW, DESTROYWINDOW, and MOVEWINDOW, etc., all of them use the window messages, and the messages we can click on the click mouse are also a window message. Command message, this is a special window message, who uses a user request sent from a window to another window, such as pressing a button, he will send a command message to the main window. The control notification message refers to such a message. There are some things in one window that need to notify the parent window. The notification message is only available for standard window controls such as buttons, list boxes, combo boxs, edit boxes, and Windows public controls such as tree-like views, list views, etc. For example, click or double-click a control, select some text in the control, and the scroll bar of the operating control will generate a notification message. She is similar to the command message, when the user interacts with the control window, the control notification message will be sent from the control window to its main window. However, the existence of such messages is not to handle user commands, but to make the main window to change controls, such as loading, display data. For example, pressing a button, the message sent to the parent window can also be seen as a control notification message; click the message generated by the mouse to process directly by the main window, and then hand it over to the control window processing. The window message and control notification message is mainly processed by the window class directly or indirectly by the CWND class. Relative to the window message and control notification message, the processing object of the command message is much wide, but it can not only be processed by the window class, but also by the document class, document template class, and application classes. Since the control notification message is important, people use more, but the specific meaning often makes the beginners stepping, so I decided to list a common list for your reference:

Press twisting control BN_Clicked Users Click the button Bn_Disable button to be banned Bn_doubleClicked users Double-click the button BN_HILITE with / homework button BN_PAINT button should be returned BN_UNHILITE

Combination box control CBN_Closeup combination box list box is turned off CBN_DBLCLK user Double-click a list box for a string CBN_DropDown combination box to pull out the CBN_Editchange user modified the text in the edit box. The text in the CBN_EDITUPDATE edit box is about to update the CBN_KILLFOCUS Combination box Losing Input Focus CBN_SELCHANGE Select a CBN_SELENDCANCEL user selection in the combo box Should be canceled CBN_SELENDOK user's selection is a legal CBN_SETFOCUS Combination box Get Input Focus Editing Frame Control En_Change Edit box Signature EN_ERRSPACE edit box memory EN_HSCROLL users Click the horizontal scroll bar en_killfocus edit box is losing the input focus en_maxtext Inserted content Truncated EN_SETFOCUS Edit box Get the input focus en_update Edit box text will be updated EN_VSCROLL users Click the vertical scroll bar message meaning

List box control LBN_DBLCLK users Double-click a LBN_ERRSPACE list box memory is not enough LBN_KILLFOCUS list box is losing input focus LBN_SELCANCANCEL Select Cancel LBN_SELCHANGE Select another LBN_SETFOCUS list box to get input focus

转载请注明原文地址:https://www.9cbs.com/read-13110.html

New Post(0)