Deep analysis of the news in the VC (on)

zhaozj2021-02-16  52

Summary: Windows programming and DOS programming, a big difference is that Windows programming is event driver, and messaging is delivered. So, doing Windows programming, you must have a clear understanding of the message mechanism. This article hopes to be a comprehensive discussion on the delivery of the news. Due to the child's first school VC, there may be some mistakes, but also criticized Finger, correct.

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 of the message; Message constant identifier, that is, us usually The specific additional information of the message number WPARAM WPARAM; 32-bit messages, the exact meaning depends on the message value LParam LPARAM; 32-bit messages specific additional information, the exact meaning depends on the message value DWord Time; the time POINT PT when the message is created; The position of the mouse / cursor at the time of the message is created in the screen coordinate system} MSG; the message can be generated by the 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 Cycling message 0x0220 ---- 0x0230 more document messages 0x03E0 ---- 0x03E8 DDE message 0x0400 WM_USER 0X8000 WM_APP 0x0400 ---- 0x7FFF application custom private message

What kinds of 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 very important, people use more, but the specific meaning often makes the beginners to stepping, so I decide to list a common list for your reference: Press twisting control Bn_Clicked Users Click the button Bn_Disable button Ball BN_DOUBLECLICKED user double-click the button BN_HILITE with / housing BN_PAINT button Shooting BN_UNHILITE Shift Should Be Remove the Combination Box Control CBN_CLOSEUP Combination Box Ship Closed CBN_DBLCLK Users Double-click a String CBN_DropDown Combination Box Pull out the CBN_Editchange user modified the text in the edit box in the text of the CBN_EDITUPDATE edit box. The CBN_ERRSPACE box memory is not enough CBN_KILLFOCUS combination box Lost input focus CBN_SELCHANGE Select a CBN_SELENDCANCANCEL user selection should be canceled CBN_SELENDOK user selection It is a legal CBN_SETFOCUS combination box to get the input focus editing box control en_change edit box text EN_ERRSPACE edit box memory insufficient en_hscroll user Click the horizontal scroll bar en_killfocus edit box is losing the input focus EN_MAXTEXT insertion The content is truncated EN_SETFOCUS edit box Get input focus EN_UPDATE text edit box will be updated EN_VSCROLL user clicks the vertical scroll bar LBN_DBLCLK user message meaning a list box control list box, double-click a LBN_ERRSPACE enough memory LBN_KILLFOCUS list box is losing the input focus LBN_SELCANCEL another selection is canceled LBN_SELCHANGE chosen LBN_SETFOCUS The list box gets the input focus is not finished (forcessitating ...)

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

New Post(0)