---- C Builder is worthy of Borland's excellent products, using it to develop Windows programs very fast, but you will also find some restrictions in programming, so you can't achieve your own ideas. For example, you can't modify the system menu of the form; for example, when using the tracking bar, you can't find the StartTrack and EndTrack events, and your procedure requires these two events. In Windows API programming, you will not have these troubles, just process the WM_SYSCOMMAND and WM_HSCROLL (or WM_VSCROLL) messages, the above functions can be implemented. The disadvantage of the Windows API is that it is very troublesome, too much time to consume on the details, but its function is the most powerful. The VCL of C Builder is functionally only a subset because the VCL is encapsulated on the API, and some unused functions are prepared. But the programmer's imagination is not encapsulated. They always have a big enthusiasm to achieve other ideas, modify the system menu and add StartTrack and NDTRACK events for the tracking bar. But the VCL does not have these functions, what should I do? ---- Fortunately, Borland did not block roads, but left a back door - allowing programmers to intercept and handle Windows messages, just like API programming. So, the way is ... ---- Intercepting Windows Messages requires the following steps: ---- In the table single header file (such as Unit1.h) ---- 1. Create a message mapping table in the class declaration, Trepate the handling of a message to the custom message processing function. Begin_MESSAGE_MAP Message_Handler (Windows Message Name, TMessage, Message Processing Function Name) Message_Handler (...) End_MESSAGE_MAP (TFORM) ---- 2. Declaration Message Processing Functions within the Private area of class declarations. Private: // user declarations void __fastcall message processing function name (TMESSAGE & Message); in the form file (such as Unit1.cpp) ---- 3. Write the message processing function, here you need the features you need. For example, void __fastcall mainform :: onwmhscroll (tMersage & Message)} ... // Add your own code TFORM :: Dispatch (& Message); {--- Explanation ---- 1. About TMESSAGE ---- TMessage is a VCL predefined structure, defined as follows: struct tMessage {unsigned int msg; // message int wparam; // word parameter int Lparam; // long word parameter int result; // message result}; ---- 2 . About TForm :: Dispatch (& Message) ---- Custom Message Processing Function It is best to add a TForm :: Dispatch (& Message), this sentence is to let the message continue to pass. If this sentence is not, the message will be completely intercepted, and the VCL class may fail to achieve normal functions due to the message. ---- Example 1: Modify the System Menu ---- There are some programs, the main window is small, the menu is not, if you want to join about or setup dialogs, the best way is to take the system menu. In Windows API programming, modify the system menu is the same as implementing other functions, not too easy, and it will not be too difficult.
However, in C Builder, the table class (TFORM) does not provide any properties and methods of the system menu, implementing other features, and the modification system menu seems to be difficult to go on the sky. ---- Fortunately, Borland allows programmers to process Window messages, so the opportunity is coming! First, modify the system menu with the Window API function to assume the form name MAINFORM, set the mainform :: oncreate () function: 1. Get the system menu handle with getSystemMenu (Mainform-> Handle, False); 2. Use appendmenu, deletementu, modifyMenu function Modify the system menu to assign the new ID number to a custom menu item. At this time, you can see that the system menu is also modified, but the custom menu item cannot be responded. Second, intercept the WM_SYSCOMMAND message in response to the custom menu item (such as Unit1.h) 1. Add a message response table at the end of the form class, get the processing of the WM_SYSCOMMAND message begin_message_map message_handler (wm_syscommand, tmessage, onwmsysCommand) END_MESSAGE_MAP (TFORM) 2. Add message processing function declaration inside the form class defined private: // user declarations void __fastcall onwmsysCommand (TMESSAGE & Message); in the form file (such as Unit1.h) 3. Write a message response function void __fastcall TForm1 :: OnWMSysCommand (TMessage & Message) {if (Message.WParam == ID_SysMenu_MyItem) {// Your Code Here, Do Something} TForm :: Dispatch (& Message);} example two: to increase OnStartTrack track and field events OnEndTrack When the tracking column is used for progress control, OnStartTrack and OneendTrack are likely to be the event you need. For example, when controlling multimedia play progress, when the user moves the slider, you will need the onStartTrack event to stop playback, you need the OneendTrack event to locate the new play position. But Borland did not provide these two events, and I have such programming enthusiasts to self-reliance, and the idea of intercepting Windows messages. First, intercept the WM_HSCROLL message, add the onStartTrack and OneendTrack event to the trackball (such as Unit.h) (such as unit.h) 1. Add a message response table at the end of the form class, and give the WM_HSCROLL message handle to the ONWMHScroll function. Begin_MESSAGE_MAP Message_Handler (WM_HSCROLL, TMESSAGE, ONWMHSCROL) End_MESSAGE_MAP (TFORM) 2. Join the ONWMHScroll function declaration within the Private area defined by the form class. Private: // user declarations void __fastcall onwmhscroll (TMESSAGE & Message); 3. Add StartTrack and EndTrack function declaration within the Private area defined by the form class.