Work note-pull message mechanism and note message mechanism
The message mechanism for servers and mobile phones is implemented for the first time. There is no push mechanism and messages can only be pulled. It seems a little complicated ~
This is the new flowchart. I don't know what the problem is. I hope you can give some comments or introduce some useful push methods ~
Click to view the chart
Message Mechanism
The message ring not only corresponds to windows, but also to threads.
For a windowless win32 program, messages are sent to the main thread of the program.
In addition, the differences between "no window created" and "No window displayed" must be different. The message ring takes effect when the window is not displayed. You can use the message ring once a handle is created.
Understanding windows Message Mechanism
Message mechanism is the core of Windows applications. Everything that happens in Windows can be represented by messages. messages are used to tell the operating system what happened and all Windows applications are message-driven,
In Windows, different messages are processed by different parts of the application. The MFC Library shields many underlying messages, making it easier and easier for users to process messages. For example, when a user receives a message such as a WM_MOUSEMOVE message or clicks a WM_LRBUTTONDOWN message, the user does not have to redraw the window or mouse, the MFC and application framework will do this for users. When using MFC for programming, users only need to process some high-level messages, for example, "the user clicks OK in the window" and "the user selects the fifth item in the drop-down list box, this greatly reduces the burden on programmers.
A message is composed of the message name (UINT) and two parameters (WPARAM, LPARAM. The message parameters contain important information. For example, for a mouse message, LPARAM generally contains the location information of the mouse, while the WPARAM parameter contains the status information of keys such as SHIFT and CTRL when the message occurs, for different message types, the two parameters are also specific.
Message and input focus
Windows is a message-oriented system. Applications can only passively wait for messages with user keys and cannot actively read the keyboard status. That is to say, every time a key is pressed on the keyboard, the system sends a key message to the window, telling it that a key is pressed. If you move the mouse a moment, the system sends a message accordingly, and pass the coordinates of the mouse to the window.
Windows can execute many programs at the same time, but there is only one keyboard. How can I determine which window receives messages from the keyboard and mouse? This problem can be solved using inpuut focus technology. As long as a window gets the input focus, it will not only be raised to the front of the screen, but the color will also be different. All keyboard messages will be directed to the window, this window also becomes an "activity window ".
How do I obtain the input focus in the window? The window clicked by the mouse usually gets the input focus. In addition, the program itself can also use SetFocus () to specify which window has the input focus.
CWnd * CWnd: SetFocus ();
If you call the SetFocus () member function of a window, the window gets the input focus, which returns the previous window with the input focus.
If the input focus of a window is stolen, the Windows system sends the WM_KILLFOCUS message to the window that loses the input focus, and notifies the window of a pointer to get the input focus. The window that obtains the input focus will receive the WM_SETFOCUS message.
The message response functions are:
Afx_msg void OnKillFocus (CWnd * pNewWnd );
The parameter is the pointer to the window that gets the input focus.
Afx_msg void OnSetFocus (CWnd * pOldWnd );
The parameter is the pointer of the window that loses the input focus.
Message category
Many messages are predefined in Windows. Each message has a macro definition, that is, an image string is used to identify the message. A series of # define statements associate the message with a specific value, in the header file WinUser. h find these macro definitions, such
# Define WM_PAINT 120
You can use the message name "WM_PAINT" in the program to access it. Other messages include:
# Define WM_MOUSEMOVE 0x0200
# Define WM_LBUTTONDOWN 0x0201
# Define WM_LBUTTONUP 0x0202
# Define WM_LBUTTONDBLCLK 0x0203
# Define WM_RBUTTONDOWN 0x020 ...... remaining full text>