The Remaining Code
The rest of my sample code in Listing 1 is primarily event handler code:
- The OnQuit function runs when the user chooses File > Exit, and the code calls Close(), which closes the window, causing the Show() call in MyApp::OnInit() to return. OnInit then finishes, and the program shuts down.
- The OnAbout function runs when the user chooses Help > About. This code demonstrates how to pop up a simple message box by calling the wxMessageBox function.
- The OnButton1 and OnButton2 functions don’t do a whole lot other than show you that you can have different event-handling functions for different controls. They just pop up a message box as well.
- The OnListBoxDoubleClick function is called when the user double-clicks an
item in the list box. In this code, I demonstrate a cool feature about text
boxes, and I also show how to retrieve the selected string from the list box.
Notice how I write text to this panel’s text box:
*textLog << "ListBox double click string is: \n";
The textLog variable is the pointer to wxTextCtrl that I created earlier. To add text to the text box, I dereference the pointer to get the object itself, and simply write to it like I would with the cout variable. That’s a pretty useful feature for adding debugging output to your programs without having to mess around with a console.
To access the selected value of the list box, I simply call GetString on the list box:
*textLog << event.GetString();