Creating a List of Names
Task :
The previous program allowed the user to enter a first and a second name. These could then be displayed in an ordinary window and a form view. This program should now be modified to allow a list of names to be displayed and stored. The program may keep the title names.
Instructions :
- This program uses a POSITION type to allow the both views to access the list of names. As a result, all of the Get and Set functions previously in the Document should be removed. The pointer to the CName class should also be removed.
- Define a TypedPtrList in the Document.
- Define the POSITION in the Document.
- Create a GetCurrentItem() function in the Document.
- Edit the AddNames() function in the Document.
- Edit the OnDraw() function in the FormView class to all the current item to be displayed.
- To allow the list of names to be displayed GetNextItem() and GetHeadPosition() functions must be added to the Document.
- Edit the OnDraw() function in the standard view to display the list of names.
Help :
The MSDN library provides a sample program, COLLECT, which displays some of the features of the CTypedPtrList class.
Click here for a worked example
Click here for the source code
Click here to return to menu