When the user clicks on the "Add" button in our "List of Names" window, we want to pop open the "Add a name" window we just created. We want it to operate as a modal window. (ie, All other GUI windows we opened will be disabled until the "Add a name" window is finally closed).

The first thing we should do is decide upon a filename for our child window layout script. Let's name it AddAName.rex. Select the File -> Save as menu command and save the child script with that name. Just for simplicity, save it in the same directory where you will save your main script.

Next, we need to go back to our Main Window Layout script. Flip to its editor window. Let's save it with a name of "ListOfNames.rex".

Note: It isn't necessary to save your Window Layout scripts each time you make changes to them, but you should save them at least once in order to give them something other than the default name that Programmer Center created for you. In particular, the names of child window scripts are important, because we need to reference the child script's filename when we use its window in our main script.

Let's add some code to our "Add" button (in the Main script window) to present this child window. In order to present a child window, you need to create it as a REXX Object. You need to pick out an object variable name to refer to the child window. For simplicity, we'll simply use the same name as the child script's filename (minus the .REX extension). So, to present our child script window, we put the following instructions in our subroutine to handle the "Add" button's CLICK event:

WM_CLICK_NameAdd:
   /* Present the "Add a name" window. Use an object variable name of AddAName. */
   CreateObject("AddAName.rex", , , -1, "NORMAL")

   RETURN
The -1 passed to CreateObject ensures that the window is created modal. The NORMAL arg makes the window appear on the screen.

Run your main script via the Run -> Execute script menu command. Click on the Add button and you should see the "Add a name" window open. Notice that you will be unable to manipulate your main window while this child window is open. This is the effect that a child modal window has.

You'll also note that clicking on the "OK" button in the child window does nothing. This is because we haven't yet added a handler for its CLICK event.

You can close the "Add a name" window with its close box, and then you'll be able to also close the "List of names" window to end the script. Or, just select the Run -> Halt script menu command.