//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;
}
}
這個思路不太對,使用選單默認保存檔案后,下次打開串列視圖是空白的。
我希望下一次打開程式時顯示的是上次編輯后的內容,應該怎么改正?
uj5u.com熱心網友回復:
重新 插入 到 Listctrluj5u.com熱心網友回復:
先解決 1 保存的內容完整么? 2 從檔案讀出能區分出行列么?uj5u.com熱心網友回復:
寫內容---保存---重繪(多種原因)----寫內容到視窗uj5u.com熱心網友回復:
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!");
}
uj5u.com熱心網友回復:
都有了
// save to file
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!");
}
uj5u.com熱心網友回復:
掉了一句flist.Close();
// fill list
FillList(0);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/28718.html
標籤:基礎類
上一篇:找個大神幫忙做H5網頁 有償的
