· Foreword
Although C Builder is a RAD-style development tool, the program designer does not need the details of the Windows message in most cases, as long as the mind is placed in the event of the function of the software element. However, because the Windows job system is one-on-telecon-driven system, the application on the architecture is naturally unable to be outside the system, and the Windows message processing power is still the event of C Builder. C Builder is indispensable.
It is undeniable that the event handling capacity provided by C Builder has a degree of completeness, but we must also recognize that in the VCL beautiful new world constructed in C Buider, there is still no leakage net fish. For example, the user's custom message, the processing of Winsock messages, and some of the Windows messages such as WM_NC **** series are not included in C Builder's object model.
In this article I will tell you how to handle Windows messages in C Builder and achieve the function that cannot be done in a general VCL component through this capability.
What is WINDOW message (Message)
Everyone knows that Windows is a job system with message driven. However, for the message itself, it is like a deep, only knows that it doesn't know how it happened, although C Builder encapsulates some Windows messages in the event (Event) system, but as a Windows programming designer, it is necessary to understand Windows Message system.
The so-called message is sent by the Windows job system to the program. It is a manner of communication in the system, for example, when moving a mouse, press the slice button, change the window size, and Windows will send a message to a notification program. Of course, in order to identify the content of the event, a number of messages are defined in the Windows system, such as WM_Paint, WM_CHAR, and more.
When the event occurs, Windows will determine that the event must be received by that program, and then send an event in a message to the program. Although hundreds of events have been included in the Windows system, the job system does not design different message structures for each event, but is described in a general structure, this structure is called in C Builder. TMESSAGE.
Of course, as the incident is different, the interpretation of the message is also different, and the exclusive structure is defined for various common messages in C Builder, and you can use them directly to interpret the message. These messages define in include / vcl / messages.hpp in the C Builder directory, you can decide to explain the TMESSAGE parameters or convert them into exclusive structures. Are you abstract? I will give an example. For WM_NCHITTEST messages, C Builder defines the exclusive structure of TwMnchittest, so you can get XPOS, YPOS equivalents directly. Or you can also get its value directly from the LPARAM of TMessage, and the end of your use is convenient. Carefully observe the two structures of TMessage and Tmnchittest, you will find that they are equivalent, that is, their size is consistent, so you can directly transform each other with mandatory transformation (this is a way similar to Union).
Struct tMessage
{
Cardinal MSG;
union
{
Struct
{
Word wparamlo;
Word wparamhi;
Word lparamlo;
Word lparamhi;
Word resultlo;
Word resulthi;
}
Struct
{
Long wparam;
Long lparam;
Long Result;
}
}
}
Struct twmnchittest
{
Cardinal MSG;
Long unused;
union
{
Struct
{
Windows :: TsmallPoint Pos;
Long Result;
}
Struct
{
Short xpos;
Short ypos;
}
}
}
After receiving the message, the program must handle the message. If not processed, it can be handed over to the Windows's internal processing program. If the program requires the return value, it can be transferred at this time, and Windows will This value is transmitted back to the caller. This completes the program of message delivery.
Is it complicated? not at all! Learn about the WINDOWS message system, let's see if you can use it to do something interesting!