Message-based, event-driven

Source: Internet
Author: User

WindowsProgramDepends on the externalEventComeDriver. In other words, the program keeps waiting (using a while loop ),Wait for any possible inputAnd then doJudgmentAnd then make the appropriateProcessing.

The preceding"Lose"YesbyOperating SystemCaptureToMessageForm (a Data Structure) enters the program.

The operating system passesUser Module(One of the three windows modules)CaptureEvents that occur on peripheral devices (such as the keyboard and mouse.

Two types of input obtained by the application:

ByHardwareMessages generated by the device (such as moving the mouse or pressing the keyboard) are placed inSystem queue)Medium

By windowsSystemOr otherWindowsProgramThe sent message is placed inApplication queue).

From the application's perspective, a message is a message. There is no big difference in where it comes from or where it is stored.The getmessage API gets a message, and the life of the program is promoted by it.

All GUI systems, including unix x Windows and OS/2 Presentation manager, are like this. They are message-based event-driven systems.

It is conceivable that every Windows program should have a loop as follows:

 1   MSG;  2   While (Getmessage (& MSG, null )){  3 Translatemessage (& MSG );  4 Dispatchmessage (& MSG );  5   }  6   7   //  The above functions are all Windows API function messages, that is, the MSG structure shown above, which is actually a data format defined in Windows:  8   /*  Queued message structure */  9 Typedef Struct  Tagmsg  10   {  11   Hwnd;  12 Uint message; //  Wm_xxx, such as wm_mousemove, wm_size...  13   Wparam;  14   Lparam;  15  DWORD time;  16   Point pt;  17 } MSG;

 

 

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.