Preface
In the previous article, we added a button to the most basic form. With the button, we certainly need to play the role of the button, as we all know, the most basic function of a button is to interact with a computer through a user's click event. If you have. net winform, WPF or Java GUI development, I believe you have done this operation countless times, and this operation is very convenient, with the help of powerful ide such as, it is easy to create a form, add a button, add a click event to the button, and listen to the event. When the event is triggered, the event processing function is called back and the corresponding operations are executed. In the development of modern forms applications, you often see events rather than message processing, because the object-oriented language encapsulates message processing, makes development easier. So can the go language be like this? The answer is yes. However, today we do not do this. We still use the traditional message processing method to process click messages. As for encapsulation into winform similar to C, I will try again later. Even though new technologies and new languages are constantly emerging, there are still no major changes in nature, at least for the time being, it is nothing more than encapsulating inconvenient operations or obtaining better solutions through various algorithms and data institutions. Now let's start to click the message processing button today.
I. Process subform messages
After you add a button to a form, the button becomes a subform of the form. When we click the button, the corresponding message is generated. However, as we know before, if the parent form retrieves various messages in the message queue and transmits the messages to the message processing function for processing, can the messages in the subform be obtained? Actually, it is okay. After the button is clicked, the child form sends a wm_command message to the parent form. Therefore, we need to add the branch of the wm_command type message to the message processing function. The final message processing function is as follows:
Note that there is an if condition in the wm_command Branch, which compares the low position of the wparam parameter in the message processing function with the ID number of the specified subform. In fact, the low position of wparam is the ID number of the subform that generates the message, so you can know the message generated by the subform through it. Here, after a message is generated, a pop-up message window as mentioned in the first article is displayed.
Ii. Meanings of wparam parameters and lparam Parameters
1. loword (wparam) ==> subform ID
2. hiword (wparam) ==> notification code
3. lparam ==> subform handle
3. Add button
Why is the subform ID compared with 1? In wm_create, the last parameter of the addbutton function is 1, because we have created a button with ID 1. In addition to the subform ID to determine which subform generates the message, we can also use the window handle to determine the message, as shown in the wm_command comment. The addbutton function is as follows:
The previous article has discussed how to create a subform, so I will not talk about it here. The key is the last Id parameter, which is the newly added subform ID parameter in this article.
Final effect:
This is today. continue later ~