Serailize problem
I use SDI with DOC/VIEW architecture. I have a CString vector that stroes
some files' path. I want to let the program to save the CString vector when
the program exist, and load back to the CString vector when the program
excutes next time. So I can get the files' path. Below are part of source
code.
//***************************************
in .h:
class CMyDoc : public CDocument
{
protected: // create from serialization only
CePhotoSyncDoc();
DECLARE_DYNCREATE(CePhotoSyncDoc)
public:
std::vector<CString> m_vThuSelFileName;
}
-------------------------------------------------------------------------------
in .cpp:
IMPLEMENT_DYNCREATE(CMyDoc, CDocument)
void CMyDoc::Serialize(CArchive& ar)
{
CObject::Serialize( ar );
unsigned int vectorSize = 0;
if(ar.IsStoring())
{
// TODO: add storing code here
ar << m_vThuSelFileName.size();
for(unsigned int i = 0; i < m_vThuSelFileName.size(); i ++)
{
ar << m_vThuSelFileName.at(i);
}
}
else
{
// TODO: add loading code here
ar >> vectorSize;
for(unsigned int i = 0; i < vectorSize; i ++)
{
ar >> m_vThuSelFileName.at(i);
}
}
}
//**********************************************
Question1. How?
But I don't know how to let the program(not user clicking "Save As" or "Save
File") to utilize the DOC's serialization function storing the CString vector
automaticly, and let the program loading back the CString vector automaticly.
Any suggestions? Thanks.
Question2. When?
And assume I know how to do that. Should I do the operation when user click
the exist button or x button at the top right position of the window?