After you have associated a REXX variable with a control, then you can handle events that happen with that control. Typically, there are many types of events that can happen with a control. For example, when the user clicks on our names list box, it generates an event that tells us the list box has been given "the focus" (ie, it is ready for the user to operate it). When the user clicks on an item in the list, another event is generated to indicate that an item is selected.

Your Window Layout script can choose to handle any particular types of events it wishes from any particular controls. For events that you have no interest in, you do not need to do anything. For each type of event you choose to handle, you need a subroutine specifically for that event on that control. The subroutine must be given a particular (label) name, but the Resource Editor will create that label for you.

For our "List of Names" window, we do not need to receive any events from the listbox. We'll simply let Reginald manage the user interaction with it. But we do want to know when the user clicks on the Add or Delete PUSH controls. As luck would have it, when the user clicks on a PUSH control, it generates a "CLICK" event.

So, let's first handle the CLICK event for the "Add" control. Move the mouse over the Add control, and double-click the left mouse button. This brings up the PUSH Properties dialog, which should now be a familiar operation. On the right side of this dialog, you'll see a box labeled Events. And in this box will be various events that happen with a PUSH control. Click on the event named CLICK to highlight it as so:

Now click on the button labeled Add event handler.

The PUSH Properties dialog will disappear, and a new subroutine will have been added to (the end of) your window layout script as so:

WM_CLICK_NameAdd:
   RETURN
You'll notice that this subroutine's name is comprised of "WM_", the event, followed by an underscore, and then the name of the REXX variable we associated with our Add control. You must not change the name of this subroutine.

Now whenever the user clicks on the Add button, Reginald will call this subroutine. Just for a test, let's add a call to GuiSay() to pop up a message box as so:

WM_CLICK_NameAdd:
   /* Display a message. */
   GuiSay("User clicked the Add button")
   RETURN
After making the above change to the script, let's try running it (via the Run -> Execute script menu command). When you click on the Add button, you should see the message box pop up. Reginald has indeed called our subroutine for a CLICK event on our Add button.

But if you click on the Delete button, you'll notice that nothing happens. This is because we haven't yet added a handler for its CLICK event. (ie, Each control has its own event handlers -- even controls that are of the same type such as these two PUSH controls).

You can end your script simply by closing the "List of Names" window.

Now go back to the "List of Names" window we're designing and double-click on the Delete control to bring up its PUSH Properties dialog. Select the CLICK event and click on Add event handler. You'll see another subroutine added to our Window Layout script as so:

WM_CLICK_NameDelete:
   RETURN
Notice that the subroutine name ends with the REXX variable name we associated with the Delete control (ie, NameDelete). To test this, let's add another GuiSay() call as so, and run the script:
WM_CLICK_NameDelete:
   /* Display a message. */
   GuiSay("User clicked the Delete button")
   RETURN
You should now see a message box when you click on the Delete button as well.