//CMonView:CListView
void CMonView::Save()
{
CString savestr1 = GetDocument()->savestr;
int nRow=m_listCtrl->GetItemCount();
int nCol = m_listCtrl->GetHeaderCtrl()->GetItemCount();
CString a[3][7];
for (int i = 0; i < nRow; i++)
{
for (int j = 0; j < nCol; j++)
savestr1.Format("%s", m_listCtrl->GetItemText(i,j));
}
}
//CBackDoc
CString savestr;
void CBackDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << savestr;
}
else
{
ar >> savestr;
}
}
这个思路不太对,使用菜单默认保存文件后,下次打开列表视图是空白的。
我希望下一次打开程序时显示的是上次编辑后的内容,应该怎么改正?
void CMonView::Save()
{
CString savestr1 = GetDocument()->savestr;
int nRow=m_listCtrl->GetItemCount();
int nCol = m_listCtrl->GetHeaderCtrl()->GetItemCount();
CString a[3][7];
for (int i = 0; i < nRow; i++)
{
for (int j = 0; j < nCol; j++)
savestr1.Format("%s", m_listCtrl->GetItemText(i,j));
}
}
//CBackDoc
CString savestr;
void CBackDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << savestr;
}
else
{
ar >> savestr;
}
}
这个思路不太对,使用菜单默认保存文件后,下次打开列表视图是空白的。
我希望下一次打开程序时显示的是上次编辑后的内容,应该怎么改正?
vector<FileInfo>fileList;
typedef struct FileInfo
{
string szFileName;
string szFilePath;
string szCreateTime;
}FileInfo;// save to file
void CShowdirDlg::OnButton6()
{
// TODO: Add your control notification handler code here
CFile flist;
flist.Open("ListSaved.txt",CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive);
UINT nCount=fileList.size();
UINT i;
CString empty;
CString name;
CString time;
CString mypath;
for(i=0;i<nCount;i++)
{
if(i>=nCount) break;
name.Format("%s\r\n",fileList[i].szFileName.c_str());
flist.Write(name,name.GetLength());
time.Format("%s\r\n",fileList[i].szCreateTime.c_str());
flist.Write(time,time.GetLength());
mypath.Format("%s\r\n",fileList[i].szFilePath.c_str());
flist.Write(mypath,mypath.GetLength());
}
flist.Close();
AfxMessageBox("ListCtrl saved!");
}
void CShowdirDlg::OnButton6()
{
// TODO: Add your control notification handler code here
CStdioFile flist;
flist.Open("ListSaved.txt",CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive);
UINT nCount=fileList.size();
UINT i;
for(i=0;i<nCount;i++)
{
if(i>=nCount) break;
flist.WriteString(fileList[i].szFileName.c_str());
flist.WriteString(fileList[i].szCreateTime.c_str());
flist.WriteString(fileList[i].szFilePath.c_str());
}
flist.Close();
AfxMessageBox("ListCtrl saved!");
}
// load
void CShowdirDlg::OnButton7()
{
// TODO: Add your control notification handler code here
FileInfo finfo;
char buf[260];
int col=0;
fileList.empty();
CStdioFile flist;
flist.Open("ListSaved.txt",CFile::modeRead | CFile::shareExclusive);
while(flist.ReadString(buf, 260))
{
switch (col)
{
case 0: finfo.szFileName=buf;break;
case 1: finfo.szCreateTime=buf;break;
case 2: finfo.szFilePath=buf;break;
}
col++;
if(col==3)
{
col %=3;
fileList.push_back(finfo);
}
}
// fill list
FillList(0);
AfxMessageBox("ListSaved.txt loaded!");
}
flist.Close();
// fill list
FillList(0);