Windows Messaging Mechanism

Source: Internet
Author: User

I. Windows Messaging mechanism processing process

(1) Windows establishes a message queue for each executing Windows application, which is the application queue that holds messages for various windows that the program may create.

When an application event occurs, Windows translates the event into a message and puts the message in the application's message queue.

(2) The application retrieves event messages from the message queue via GetMessage and distributes them to the message handlers of the corresponding window.

 while 0 0 )     {//  Converts a virtual key message to a character message    translatemessage (&msg);        // Pass the MSG structure back to Windows and Windows    will // the message is sent to the appropriate window message handler function    DispatchMessage (&msg);    }

Two. Windows Messaging Mechanism essentials

(1) Window procedure

Each window will have a callback function called a window procedure (WNDPROC), and the system will call back with this window procedure to process the message when the window receives the message

(2) Message type

Message types are divided into system-defined messages (window messages, command messages, control notification messages), and user-defined messages

A. Window message: Related to the internal workings of the window, such as window creation, drawing, display, destruction, etc.

B. Command message: Related to handling user requests, such as clicking a menu item or toolbar or control

C. Control notification: WM_NOTIFY message, most flexible message format

D. User-defined message Wm_user + 100 (habitual)

(3) Message Queuing

A. System Message Queuing

B. Thread Message Queuing: Each GUI thread maintains such a thread message queue. This queue is only created when the thread calls the GDI function, and the default part is created

The message in the thread message queue is then sent to the appropriate window procedure for processing.

Note: wm_paint, wm_time in thread Message Queuing will only be processed if there are no other messages in the queue

Windows Messaging Mechanism

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.