Message Processing Mechanism and window process function of VC ++ learning notes

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.