Events Drive Apps
We've built our application's interface. We started with a simple window and added a textbox and two buttons. And though we can type in the textbox and click the buttons, the application doesn't do anything. We have to tell it how to respond to those "user events," or just "events."
So, first off, let's add the code that will run when the user clicks the "Quit" button.
Generally, you will create a procedure for each "event" the user can perform. In this simple name-scramble application, we're going to be concerned with two events:
So, we need to create two procedures and "attach" them to the controls or events that will call them.
wxEuphoria's Quit Procedure
Here's the code we need to add to our wxEuphoria scramble application. You will place this right after the setup() procedure.
procedure Click_QuitButton(atom this, atom event_type, atom id, atom event )
exit_main()
end procedure
set_event_handler(QuitButton, get_id(QuitButton), wxEVT_COMMAND_BUTTON_CLICKED, routine_id( "Click_QuitButton" ))
It's the set_event_handler() procedure that tells wxEuphoria what procedure to call when the user clicks the "Quit" button.
Win32Lib's Quit Procedure
Win32Lib has a built-in quit procedure we can call from any widget. Modify the 'Quit' button's definition string to the following:
"Button, Quit,"
& "at=(editName-88, **)," -- left=previous right - 88, top=previous top
& "width=88,"
& "flag=autoclose" -- This button will close the window.
Next, we'll add code for the "Scramble Me" button click event.