The process and application of message processing in C + + Builder

Source: Internet
Author: User
Tags message queue

C + + Builder as a RAD tool for program development, its new visual programming environment, component-oriented development model will undoubtedly greatly improve the programming efficiency. It encapsulates the intricacies of Windows messages and APIs, and programmers in most cases ignore the details of Windows messages as long as they focus on the component's event-handling functions. However, after all, the Windows operating system is a message-driven system, running its application, naturally can not out of the system, so master and use message processing, some problems can be handled with a multiplier effect.

Although C + + Builder's VCL controls encapsulate most commonly used messages, the event-handling capabilities provided by C + + Builder are quite complete, but when handling C + + Builder undefined Windows messages or custom messages, master C + + Builder Internal message processing mechanism is still very necessary. The following, starting from the Windows operating system message-driven mechanism, discusses the encapsulation, delivery and processing mechanism of messages in the VCL control of C + + builder, and finally, the application instance of the new message processing process as the verification and practice of the content.

Windows message-driven mechanism

Windows is a message-driven operating system, and Windows messages provide the means to communicate between applications and applications and between applications and Windows systems.

There is a system message queue in Windows, and for each executing Windows application, the system establishes a message queue, an application queue, that holds messages for the various windows that the program might create. The application contains a piece of code called a "message loop" that is used to retrieve the messages from the message queue and distribute them to the appropriate window functions.

The message loop code is a program segment similar to the following in the main function WinMain () in the application:

  while(GetMessage(&&msg,NULL,NULL,NULL))
  { //从消息队列中取得消息
  TranslateMessage(&&msg);
  //检索并生成字符消息WM_CHAR
  DispatchMessage(&&msg);
  //将消息发送给相应的窗口函数
   }

This shows that the so-called "message cycle", is actually a program cycle.

Related Article

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.