In-depth VCL understands BCB Message Mechanism (1)

zhaozj2021-02-08  225

In-depth

VCL

understanding

BCB

Message mechanism

Method 1 Written by cker

The technical content disclosed herein is from the disclosure of the Internet. After the CKer is sorted out, it is sticked to the netizens, just called the original. "Every time I find a wonderful article on foreign websites, I will secretly sigh, why is it difficult to have this article in the Chinese website? In fact, everyone understands everyone. Today, the brothers who study Windows programming know the importance of the message mechanism. Therefore, understanding the message mechanism has also become an indispensable homework. Everyone knows that the core of Borland's C Builder and Delphi is VCL. As a development tool on the Win32 platform, the message mechanism of the package Windows is essentially indispensable. So, what are the methods for processing messages in C Builder? Where is the difference between them? If you are very clear, huh, sorry, please turn off this window. If you don't know, then I will go deep into the source code of VCL. "Note: BCB has only Professional and Enterprise versions with VCL source. Of course, everyone's version has source. I have not guess: -) "method 1. Use message mapping (Message Map) to overload TOBJECT's Dispatch virtual member function This method is much available. The form is as follows Begin_Message_Map VCL_MESSAGE_HANDLER (...) end_message_map (...) But these sentences are too awkward, and there is no such definition in the C standard. It is obvious that this is obviously a macro definition. What come to the end? When CKER saw them for the first time, Best can't understand.

Oh, don't go deep into VCL, how can it understand? In / Borland / CBuilder5 / include / vcl, find sysmac.h, which has the following precompilation macro definition: #define begin_Message_Map Virtual void __fastcall dispatch (void * message) / {/ switch ((pMessage) -> msg) -> msg) / {#Define vcl_Message_Handler (MSG, Type, Meth) / Case Msg: / Meth (* ((Type *))); / Break; // Note: ATL Defines a Message_Handler Macro Which Conflicts with VCl's Macro. The // VCL macro has been renamed to VCL_MESSAGE_HANDLER If you are not using ATL, // MESSAGE_HANDLER is defined as in previous versions of BCB.file:.!! // # if defined (USING_ATL) && defined (USING_ATLVCL) && defined (INC_ATL_HEADERS)! #define MESSAGE_HANDLER VCL_MESSAGE_HANDLER # endif // ATL_COMPAT # define END_MESSAGE_MAP (base) default: / base :: Dispatch (Message); / break; /} /} such an example in the following: BEGIN_MESSAGE_MAP VCL_MESSAGE_HANDLER (WM_PAINT, TMessage, OnPaint) END_MESSAGE_MAP ( TFORM1) When the precompilation, it is deployed as the following code virtual void __fastcall dispatch (Voi D * Message) {Switch ((pMessage) -> msg) {copy wm_paint: onpaint (* ((tMESSAGE *) message))); // message response handle, that is, the member function of the response message, in Form1 Define Break; default: form1 :: dispatch (message); Break;}} This is pleasing, right. There are two points to explain this method: 1. Virtual void __fastcall dispatch (void * message) This virtual method is the first to find in the definition of TOBJECT. Open the help of the BCB, find the TForm's Method (Method), you will find that it is clear that the Dispatch method inherits from TOBJECT. If you care about the VCL's inheritance mechanism, you will find that TOBJECT is the base class of all VCL objects. Abstraction of TOBJECT condenses the heart of Borland engineers. If you are interested. You should look at the definition of TOBJECT. Obviously, all TOBJECT subclasses can overreload the dispatch method of the base class to implement their own message call.

转载请注明原文地址:https://www.9cbs.com/read-2203.html

New Post(0)