Yr interview-differences between Windows message mechanism process and sendmessage and portmessage

Source: Internet
Author: User

This is another interview question. When I come back, I will summarize it.

The biggest feature of Windows is its graphical operation interface, which is based on its message processing mechanism.

I. There is a system message queue in windows. For every running Windows application, the system creates an application queue-"message queue"-to store messages in various Windows that may be created ". There is a piece of code called "message loop" in the application.

While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}

The MSG variable is a MSG-type structure. The MSG type is defined in winuser. h as follows:
Typedef struct tagmsg
{
Hwnd;
Uint message;
Wparam;
Lparam;
DWORD time;
Point pt;
}
MSG, * PMSG;

The point data type is also a structure, which is defined in windef. h as follows:
Typedef struct tagpoint
{
Long X;
Long y;
}
Point, * Ppoint;
Translatemessage (& MSG); transmits the MSG structure to Windows for some keyboard conversion. (We will discuss this in depth in chapter 6 .)
Dispatchmessage (& MSG); returns the MSG structure to Windows. Then, Windows sends the message to the appropriate window message handler for processing. In other words, Windows calls the window message processing program. In hellowin, the window message handler is the wndproc function. After the message is processed, wndproc is passed back to Windows. In this case, Windows is still in the dispatchmessage call. After the dispatchmessage call is processed, Windows returns to the hellowin program and starts the message loop from the next getmessage call.

 

 

Differences between sendmessage () and postmessage:

Both are used to send messages to applications. Postmessagex () directly adds a message to the Message Queue of the application, and exits without waiting for the program to return. sendmessage () is the opposite. After the application processes the message, it returns. I want to better reflect the relationship between the two functions:


 

What is the difference between the peekmessage function and getmessage function?


1. getmessage will not be returned until there is a suitable message, and peekmessage is just a glimpse of the message queue.
2. getmessage will delete the message from the queue, while peekmessage can set the last parameter wremovemsg to determine whether to keep the message in the queue.

 

 

 

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.