Book Image

Microsoft Visual C++ Windows Applications by Example

By : Stefan Bjornander, Stefan Björnander
Book Image

Microsoft Visual C++ Windows Applications by Example

By: Stefan Bjornander, Stefan Björnander

Overview of this book

Table of Contents (15 chapters)
Microsoft Visual C++ Windows Applications by Example
Credits
About the Author
About the Reviewer
Preface
Index

Serialization


When the users choos e the File | Open item, a file should be opened and read, when they choose the File | Save item, it should be written. Let us implement functions for loading and storing the rings. It is actually quite easy because the framework has already made most of the work. There is a function Serialize in the document class, the framework will call it for reading or writing data. We just have to add a few lines of code to Serialize in the document class. The MFC class CArray has built-in functionality to load and save the points and colors.

RingDoc.cpp

void CRingDoc::Serialize(CArchive& ar)
{
  m_pointArray.Serialize(ar);
  m_colorArray.Serialize(ar);

  if (ar.IsStoring())
  {
    ar << m_nextColor;
  }

  else
  {
    ar >> m_nextColor;
  }
}

Finally, we also ought to call the MFC method SetModifiedFlag in MouseDown in order to make sure the user cannot end the program without a warning about unsaved data.

RingDoc.cpp

void CRingDoc::MouseDown(CPoint...