For programmers for C Builder, VCL is flexible and efficient. Because the VCL is packaged on the Windows API while discarding some uncommon features, the VCL is functioning with the subset of the Windows API. VCL provides a process mechanism for most Windows messages, but how do you need to capture without processing Windows messages? C Builder uses a message mapping mechanism that links a specific Windows message in the code in the code via the message mapping table. This function is called when the window captures the message. C Builder message map defines the following form: BEGIN_MESSAGE_MAP MESSAGE_HANDLER (, , ) END_MESSAGE_MAP (ClassName) wherein: BEGIN_MESSAGE_MAP: message maps define the start statement MESSAGE_HANDLER: message processing definition END_MESSAGE_MAP: Message Mapping defined End Statement ClassName: Yes, the class name for accepting the message: Yes, the Windows Message, the message handler: Message Processing Function Name Message Structure: is the structure name used to pass to the VCL message, this structure contains processing messages All parameters, the message structure corresponding to different messages is different. Since each VCL control (whether the form or button) can receive a Windows message independently, an independent response is performed, so it is necessary to pay attention to the ClassName parameters of the message. This is now illustrated by the application definition, the application is applied. Now a form formmain, and 2 TperformanceGraph controls (can not respond to mouse events), now I want to define mouse clicks on 2 TperformanceGraph controls, and redefine mouse clicks on FormMain, the process is as follows (assuming project files for Message .bpr, program file is main.cpp, main.h): The source code is as follows: //----main.h---------------------- ---------------------------------------- # iFndef mainh # define mainh // -------------------------------------------------- --------
#include #include #include #include #include "perfgrap.h" // ------------- ---------------------------------------------- Class TFormMain: public TForm {__ published: // IDE-managed Components // ---- 2 standard TperformanceGraph control TPerformanceGraph * PerformanceGraph1; TPerformanceGraph * PerformanceGraph2; TEdit * Edit2; TEdit * Edit1; void __fastcall FormCreate (TObject * Sender); private: // User declarations // ---- Custom message processing function, where Message can not write Message Void __fastcall lbuttondton (TMESSAGE & Message); // --- user-defined function (processing message, specifically see .cpp file) void __fastcall MyWndProc1 (TMessage & message); void __fastcall MyWndProc2 (TMessage & message); // ---- function pointer is used to save the pointer TWndMethod OldWndProc1 2 TperformanceGraph message handler controls, OldWndProc2; public: // User declarations __fastcall TFormMain (Tcomponent * Owner); // ---- Message definition begin_message_map message_handler (WM_LButtondown, TMESSAGE, LBUTTONDOWN) end_MESSAGE_MAP (TFORM)}}; // --------------- -------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------- ENDIF
//----main.cpp ----------------------------------------- ------------------- # include #pragma hdrstop # include "main.h" // ------------ -------------------------------------------------- ------------- # pragma package (smart_init) #pragma link "perfgrap" #pragma resource "* .dfm" tformmain * formmain; // ----------- -------------------------------------------------- --------------_ fastcall tformmain :: tFormMain (tComponent * Owner: tform (oower) {} // ----------------- -------------------------------------------------- ------- void __fastcall tformmain :: lbuttondown (tMessage & message) {// ---- This event is activated if the mouse is clicked in the form (control outside), this event is activated (getasyncKeyState) <0) {Application-> MessageBoxa ("Form Get Messge", "Message", MB_OK); // ---- Send a mouse message to Edit2, edit2 will generate a clicked to get the focus of the phenomenon SendMessage (FormMain-> Edit2) -> Handle, Message.msg, Message.wParam, Message.lparam;}} // ----------------------------- --------------------------------------------- void __fastcall tformmain: : Formcreate (TOBJECT * Sender) { Alternatively // ---- 2 TperformanceGraph control message processing function handle OldWndProc1 = PerformanceGraph1-> WindowProc; OldWndProc2 = PerformanceGraph2-> WindowProc; PerformanceGraph1-> WindowProc = MyWndProc1; PerformanceGraph2-> WindowProc = MyWndProc2;} // --- -------------------------------------------------- ---------------------- Void __fastcall tformmain :: myWndProc1 (tMESSAGE & Message) {if (message.msg == wm_lbuttondown) // ---- If the message Is "Mouse Click Message", display information showMessage ("PerformanceGraph1 Get Message); ELSE // ---- If the message is other message, hand it over to the original processing OldWndProc1 (Message);