First draw a picture
I. Message Processing Mechanism
(1) The operating system receives the "window message" of the application and delivers the message to the Message Queue of the application.
(2) The application calls the getmessage function in the message loop to retrieve a message from the message queue. After a message is retrieved, the application can pre-process the message, for example, discard the response to a message or call translatemessage to generate a new message.
Bool getmessage (
Lpmsg, // message (MSG) struct object
Hwnd, // specify the window to receive messages
Uint wmsgfiltermin, // get the minimum value of the message
Uint wmsgfiltermax // gets the maximum value of a message.
);
The translatemessage function is used to convert a virtual key message to a character message.
The dispachmessage function assigns a message to the window, and the window process function processes the message.
You can also use the "peekmessage" function to retrieve messages.
(3) The application calls dispatchmessage to send the message back to the operating system. The message is represented by the MSG struct object, which contains the handle of the window for receiving the message. Therefore, the dispatchmessage function can always be correctly transmitted.
(4) The system uses the "pointer" of the window process function saved by the "lpfnwndproc member" of the "wndclass struct" to call the window process, processes messages (that is, the system sends messages to applications ").
Ii. Window Process Functions
The declaration of window procedure functions is as follows:
Lresult callback windowproc (
Hwnd, // The Window handle of the corresponding message
Uint umsg, // message code
Wparam, // additional parameters of the message code
Lparam // additional parameters of the message code
);
In the window procedure function, use the switch/case statement to determine what message is received during the window and how to process the message.
For example:
Lresult callback winsunproc (hwnd, uint umsg, wparam, lparam)
{
Switch (umsg)
{
Case wm_char:
.................................
Case wm_lbuttondown:
......................................
Case wm_destroy:
..................................
Default:
.................................
}
Return 0;
}
Friend, if you have any insights, you can add "Sina Weibo"/MSN Oh, starrycheng@live.com, we all discuss together, study together.
Finally, let's add one point for the whole space system.