In MFC's document/view architecture, documents store data and views display it. To take fuller advantage of this architecture (and of document serialization, covered later), move important data structures into the CDocument-derived class that AppWizard creates for you.
To move data into the document, create document-class member variables of the appropriate types. For example, suppose your program stores text data in an array. Create a document member variable, perhaps either a CString or one of MFC's array-type collection classes. Add member functions as needed to get and set the data. The following abbreviated example shows what one data structure (using a CObList collection object) looks like, along with several member functions to access the data.
class CPersonDoc : public CDocument { // ... // Attributes CObList plistPersons; // see CObList in Class Library Reference CPerson* GetPerson(UINT nPersonID); // Operations BOOL AddPerson(CPerson* pPerson); BOOL DeletePerson(UINT nPersonID); // ... };
In SHOWDIB, the most obvious data structure to move to the document is the DIB structure. You could create the appropriate DIB handle and store it in the document. Along with the data structure, move over all functions that act on the DIB. If you've already encapsulated the DIB handle within a CDIB class, that class will have the basic DIB-manipulating functions, and the document can store a CDIB or a pointer to a CDIB.