Last week we created an interface for the Professor class. When we wanted to see the list of professors, we used a menu command to get a dialog box with that list. This problem has two different lists, the professors and the courses. It would be convenient for the user to be able to see both lists and to edit each from the window containing the list.
We could use a multiple document interface, but we are essentially working with one document, so we will use a single document interface. The windows will be created using the resource workshop and the class expert to implement the operations on the course and professor lists. We will use the main window to act as a mediator which holds both the course and professor array. Pointers to these arrays are passed to the interface windows when they are initialized. The windows are initialized in the main window's SetupWindow function.
Go to the resource workshop from c++ by selecting edit menu or edit dialog from an existing class in the ClassExpert. Create a new resource of dialog type. Once you get to the dialog that determines the type of dialog use the following steps.
Since this is a window, choose the Standard Windows No Buttons for dialog type. |
|
| Next create a menu selecting new resource and add items you want for your menu. | |
| Use these settings for your window. Notice that there is a ComboBox with the list of possible menus. Select the menu you have created. | |
| This is what the window will look like. The word Course is the menu title. | |
We will use the professor information dialog from week one and add one for the course information. It will have a TEdit box for course number and a ComboBox to choose a professor. In this case the combo box is necessary, since we have no way of knowing who the professors will be when we write the program.
We will be responsible for creating the windows, displaying the windows and releasing memory used by the windows. In addition, we will override the close option for our windows, so the user can't close the professor or course window without quiting. Later in the course we will see how to open and close child windows. One problem we will put off until next week is the problem of updating windows to reflect changes made in another window. Each course contains a pointer to a professor, so when a professors information changes the changes appear immediately in the course window. If we delete a professor, there is no provision for updating the course window.
For each of the child windows we create we will add a member variable to the class of the main window. This member will be a pointer (real c++ not counted) to the window type we need. These pointers are initialized along with the counted pointers to various types of lists of items (courses and professors). In addition windows must be Created to be seen. Create a second constructor for each window which allows the main program to pass a pointer to each data structure needed to support the window. Here is the SetupWindow function for the main window in our example.
void Week1_98ListBox::SetupWindow ()
{
TListBox::SetupWindow();
// INSERT>> Your code here.
_professors = new ProfArray;
_profWind = new ProfWindow (_professors,this);
_profWind->Create();
_courses = new CourseList;
_courseWind = new CourseWindow(_professors,_courses,this);
_courseWind->Create();
}
The window pointers are real c++ pointers, so in the destructor for this window (Week1_98ListBox) we must delete _profWind and _courseWind. For now this is all we have to do with the main window. All menu operations are handled by the children of this window.
The children each have their own menus and the commands from these menus are implemented as member functions for these windows. As is always the case we use ClassExpert to implement these functions. In addition we have the usual housekeeping such as using SetupWindow to set tabs if they are needed in the listboxes and we will override the WM_CLOSE command so that users cannot close a window without leaving the program. This time we will just disable the close command for the children. To prevent the close operation from working on the children we override the handler for WM_CLOSE. All that we need to do is make it an empty function by commenting out the code provided by the system.
void CourseWindow::EvClose ()
{
// TDialog::EvClose(); I commented this out.
// INSERT>> Your code here.
}
Changes in professor data will affect various courses. In order to have changes reflected in the course
list window, we make ProfArray an array of RcPointer
To get the complete code click here.