Windows is a huge message-driven structure that sends messages to the user and responds to processing.
Message mechanism for Windows:
Windows is an object-oriented architecture in which Windows environments and applications interact through messages. After the Windows application starts executing, Windows creates a message queue for the program that holds messages that are mailed to various different windows that the program might create. The structure of messages in Message Queuing (MSG) is:
typedef struct tagmsg{
HWND hwnd;
UINT message;
WPARAM WPARAM;
LPARAM LPARAM;
DWORD time;
Point pt;
}msg;
The first member variable is the window handle used to identify the received message, and the second parameter is the message identification number, such as WM_PAINT, and the third and fourth arguments are related to the message value. The first four parameters are very important and often used, as the latter two parameters represent the time of the mailing message and the cursor position (screen coordinates) respectively. There are two ways to send messages to an application: The system sends the message "POST" to the application's message queue This is the "in-Team message" Win32 API has the corresponding function: PostMessage (), this function does not wait for the message to be processed and return While the other is a function that the system sends the message "send" to the application when it calls the window function directly, which is SendMessage () it must wait for the message to be processed before it can be returned.
For each executing Windows application, the system establishes a message queue, an application queue, that holds messages for various windows that the program might create. The application contains a piece of code called a "message loop" that is used to retrieve the messages from the message queue and distribute them to the appropriate window functions.
The message loop code is a program segment similar to the following in the main function WinMain () in the application:
while (GetMessage (&&msg,null,null,null))
{file://gets message from message queue
TranslateMessage (&&MSG);
file://retrieves and generates character messages WM_CHAR
DispatchMessage (&&MSG);
FILE://sends a message to the appropriate window function
}
This shows that the so-called "message cycle", is actually a program cycle.
Every window created by a Windows application registers a corresponding window function at the core of the system, and the window function program code is a huge switch statement that handles messages sent to the window by the message loop, which is called directly by Windows in message-driven form. Instead of being called by the application, the window function processes the message and returns control to Windows.
A modeless dialog box is a response to a message that the system processes a message and returns control to Windows after processing is completed.
Modal dialog box after the creation of the dialog box, suspend the external message, only in response to the message inside the dialog box, and external messages are all "filtered" out, until the system received Wm_destroy or WM_CLOSE, the system returns control to the modal dialog box before the creation of the thread, Continue the modal dialog box before creating the code that will execute the thread.