Part 2. Connecting the User Interface Part to the Main Part

You have created two parts, a part to implement your main function, and a part to implement the frame window in which users will interact with your program. However, the main part still needs to be connected to the visual part so that the frame window displays when you load the program. From within the VisualAge C++ IDE, follow these steps to connect the two parts:

  1. Select the Parts page of the Project section. Select the MyMain part in the Parts view. Then click the Edit Part button in the Part Launch view to open the part you selected in the Visual Builder.
  2. The Visual Builder opens in a Composition Editor view. This view shows a single part, called IVBMain1. This part is an instance of the base class IVBMain; it is used in the Visual Builder to represent the MyMain object.
  3. You need to add your MyGui part to the Composition Editor, so that you can associate it with the IVBMain1 part. From the Options menu select Add Part. In the Add Part dialog, you can specify the part name in two ways: you can type in MyGui* as the Class Name, or you can select List..., then type M in the Search String entry field to show all classes that start with M. You will see the two classes you created. Select MyGui.
  4. Click OK without giving the part a name; the Composition Editor will assign a name for you.
  5. Now you will associate the MyGui part with the nonvisual main part IVBMain1, so that your user interface is launched when main is called. Notice that the pointer is now a cross-hair. Move this cross-hair over to the free-form surface (the white area of the Composition Editor window) and left-click the mouse. A frame window with no controls in it appears. Its title bar identifies it as MyGui. You will customize this window later.
  6. Select the MyGui object, then click mouse button 2 over it.
  7. From the pop-up menu select Connect.
  8. From the cascading menu select show. This action will cause the MyGui object to be shown when main is called.
  9. A dotted line appears; move the mouse until the "star" end of the line is over the free-form surface, outside the MyGui framewindow. Click mouse button 1, then select ready from the pop-up menu.
  10. A green arrow appears, indicating that a connection has been made. To see what the arrow connects, click over it with mouse button 2 and select Open Settings. A dialog entitled Event-to-action connection - Settings appears. In the Event list, ready is selected, and under the Action list, show is selected. If your connection does not have these properties, you can change the settings her. Otherwise, click Cancel to close the dialog.
  11. Now you can generate the source code. Press Ctrl+G, or select File - Save and Generate - Part Source, to create the source files required for the MyMain part. These files were already generated for you when you first built the project; however, you have changed this part by adding the MyGui part and a connection to it.
  12. From the Composition Editor's File menu, select the configuration file name, in order to return to the project in the IDE. If you minimized the IDE earlier, you will need to restore it.

    The IDE may warn you that mymain.cpp was modified outside the IDE (because it was generated by the Visual Builder). Click OK to accept this change.

  13. Back in the IDE, build the project (click the button, or press Ctrl+Shift+B).
  14. Select the Debug page of the Project section, and click the Run button in the Run Specification pane. A console window opens, then a Frame window with no controls in it is displayed. Close the frame window by pressing Alt+F4. The console window closes when you close the Frame window.

The console window is not needed; go to the Project Options page of the Configuration section, and click the Live Find entry field at the bottom of the Options view, next to the flashlight icon . Type console in the Live Find field. You will see the console choice highlighted under Subsystem name; change this option from console to windows, apply the change (click the Apply button at the bottom of the view), and rebuild. From the Debug page of the Project section, click Run again; this time, only the graphical window opens.

Now that you have successfully created a simple visual project, it's time to start adding user interface components to it. Proceed to Part 3. Adding User Interface Controls to a Visual Part.