How to respond to messages and custom messages in C ++ Builder

xiaoxiao2021-03-06  22

Inprise (Borland) C Builder, you can respond like a message as in Delphi, just look slightly more complicated. For system-defined messages, you can respond directly: #define WM_MY_OPEN_CMDLINE_FILE (WM_USER 1) Custom Message Custom Message #define WM_MY_Search_Node (WM_USER 2) // Custom Message of Command Class Tsomeform: Public TForm { // ... other code protected classes: // void __fastcall OpenCmdLineFile response message (TMessage message); void __fastcall SearchDocumentNode (TMessage message); void __fastcall GetWindowMinMaxInfo (TWMGetMinMaxInfo message); // message achieved through the following macros the correct response BEGIN_MESSAGE_MAP MESSAGE_HANDLER (WM_MY_OPEN_CMDLINE_FILE, TMessage, OpenCmdLineFile) MESSAGE_HANDLER (WM_MY_SEARCH_NODE, TMessage, SearchDocumentNode) MESSAGE_HANDLER (WM_GETMINMAXINFO, TWMGetMinMaxInfo, GetWindowMinMaxInfo) END_MESSAGE_MAP (TForm)}; // end class // the following is the code that implements void __fastcall TSomeForm :: OpenCmdLineFile (TMessage Message) {// Directly passed the parameter lpstr lpcmdline = (lpstr) message.lparam; // from Message THIS-> HandlecMDLineFile (LPCMDLINE); // Process the parameters of the command line Return;} void __fastcall TsomeForm :: SearchDocumentNode (TMESSAGE Message) {// Response Message // Message parameters are not needed here. this-> SearchNode (); return;} void __fastcall TSomeForm :: GetWindowMinMaxInfo (TWMGetMinMaxInfo Message) {// set the minimum size of the main window MINMAXINFO * MinMaxInfo = Message.MinMaxInfo; MinMaxInfo-> ptMinTrackSize.x = 400; MinMaxInfo-> ptMinTrackSize . Y = 300;}} where: TMESSAGE and TWMGETMAXINFO type are defined: c: /programfiles/borland/cbuilder/inlucde/vcl/essages.hpp; other message response methods are the same. In addition, a corresponding message structure (such as tsearchnode_message) can be defined for custom messages, as for how to define message structures, please refer to: c: / program files / borland / cbuilder / inLuCDE / VCL / Messages.hpp

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

New Post(0)