Serializing the Data
The next three topics describe how to add the code that defines file input/output for Scribble documents. The default I/O implementation in MFC is called “serialization” (see the figure below). It provides a mechanism for making a document’s data persistent between work sessions with the program. By adding the code described in these topics, you enable the Scribble application to handle file serialization when the user clicks the Open, Save, or Save As commands from the File menu.
Suggested Reading
Note Other than filling in the serialization function, you don’t have to write any code — for example, to display the dialog boxes — to process the Open, Save, and Save As commands on the File menu. The framework supplies this code.
Serialization in Scribble
The CScribbleDoc
class declaration in ScribbleDoc.h begins with the following AppWizard-generated code, which contains an important macro invocation (DECLARE_DYNCREATE) needed for serialization (don’t add this code):
class CScribbleDoc : public CDocument
{
protected: // Create from serialization only.
CScribbleDoc( );
DECLARE_DYNCREATE( CScribbleDoc )
// Other declarations ...
};
The DECLARE_DYNCREATE macro prepares the class so that document objects can be dynamically created by the framework.