C + + Builder processing Windows messages (message)

Source: Internet
Author: User
Tags object model

Objective

Although C++builder is a RAD programming tool, programmers do not need to ignore the details of Windows messages in most cases, as long as they focus on the event-handling functions of the software component. However, since the Windows operating system is ultimately a message-driven system, the application on which the schema is based is naturally not alien to the system, and Windows message processing power is still C + + when encountering an event that is not defined by C++builder Builder a programmer's indispensable ability.

Admittedly, the event-handling capacity provided by C++builder has a certain degree of completeness, but we must also admit that there is still a slip through the vcl beautiful new World that c++buider constructs. For example, user-defined message processing, Winsock message processing, and some Windows messages such as wm_nc**** series messages are not included in the C++builder object model.

In this article I will show you how to handle Windows messages with C++builder, and through this capability, to achieve functionality that is not possible in general VCL components.

What is window message (messages)

As you all know, Windows is a set of information-driven (message driven) operating systems. However, the message itself is very secretive, only know that it does not know why, although c++builder some Windows messages encapsulated in the event system, but as a Windows programmer, it is necessary to understand the Windows information System.

The so-called message is the event that the Windows operating system sent to the program. It is the way the various objects in the system communicate, for example, when you move the mouse, press the mouse button, and change the window size, Windows sends out messages to notify the program. Of course, in order to discern the contents of the event, many messages, such as Wm_paint,wm_char, are defined in the Windows system.

When an event occurs, Windows determines that the event must be received by that program, and then the event is sent as a message to the program's window. Although hundreds of events are included in the Windows system, the operating system does not design a different message structure for each event, but rather a generic structure to describe the message, which is called Tmessage in C++builder.

Of course, as events differ, the interpretation of the message is different, and the C++builder defines the specific structure for a variety of commonly used messages, which you can use directly to interpret the message. These messages are defined in the INCLUDEVCLMESSAGES.HPP in the C++builder directory, and you can decide to interpret the tmessage parameters by themselves or directly convert them into proprietary structures. Is it abstract? Let me give you an example, in terms of the WM_NCHITTEST message, C++builder defines the exclusive structure of twmnchittest, so you can get xpos, ypos equivalents directly from it. Or you can get its value directly from Tmessage's lparam, which is convenient for you to use. If you look closely at the two structures of Tmessage and twmnchittest, you will find that they are equivalent, that is, they are of the same size, so you can convert them directly to each other (which is a bit like the Union method).

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.