Home > Software engineering >  Save the content of the CListCtrl instant MDI?
Save the content of the CListCtrl instant MDI?

Time:11-20

//CMonView: CListView
Void CMonView: : Save ()
{
Cstrings savestr1=GetDocument () - & gt; Savestr;
Int nRow=m_listCtrl - & gt; GetItemCount ();
Int nCol=m_listCtrl - & gt; GetHeaderCtrl () - & gt; GetItemCount ();
Cstrings a [3] [7];
for (int i=0; i {
For (int j=0; J & lt; NCol; J++)
Savestr1. The Format (" % s ", m_listCtrl - & gt; GetItemText (I, j));
}
}
//CBackDoc
Cstrings savestr;
Void CBackDoc: : Serialize (CArchive& Ar)
{

If (ar) IsStoring ())
{
Ar & lt; }
The else
{
Ar & gt;> Savestr;
}


}
The idea is not quite right, use the menu after the default save the file, the next open the list view is blank,
I hope the next opened the program shows the last edited content, should how to fix it?

CodePudding user response:

Reinsert the Listctrl

CodePudding user response:

Resolved first 1 content intact? 2 read from the file can distinguish between the ranks?



CodePudding user response:

Writing content - save - refresh (a variety of reasons) - writing content to Windows

CodePudding user response:

 
Vector The fileList;
Typedef struct the FileInfo
{
String szFileName;
String szFilePath;
String szCreateTime;
} the FileInfo;

//save to file
Void CShowdirDlg: : OnButton6 ()
{
//TODO: Add your the control notification handler code here
CFile flist;
Flist. Open (" ListSaved. TXT ", CFile: : modeCreate | CFile: : modeWrite | CFile: : shareExclusive);
UINT nCount=fileList. The size ();
UINT I;
Cstrings empty;
Cstrings name;
Cstrings time;
Cstrings mypath;
for(i=0; I{
If (i>=nCount) break;
Name. The Format (" % s \ r \ n ", the fileList [I] szFileName. C_str ());
Flist. Write (name, the name GetLength ());
Time. The Format (" % s \ r \ n ", the fileList [I] szCreateTime. C_str ());
Flist. Write (time, time. GetLength ());
Mypath. The Format (" % s \ r \ n ", the fileList [I] szFilePath. C_str ());
Flist. Write (mypath, mypath GetLength ());
}
Flist. Close ();
AfxMessageBox (" ListCtrl saved!" );
}

CodePudding user response:

There were
 
//save to file
Void CShowdirDlg: : OnButton6 ()
{
//TODO: Add your the control notification handler code here
CStdioFile flist;
Flist. Open (" ListSaved. TXT ", CFile: : modeCreate | CFile: : modeWrite | CFile: : shareExclusive);
UINT nCount=fileList. The size ();
UINT I;
for(i=0; 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!" );
}
//the load
Void CShowdirDlg: : OnButton7 ()
{
//TODO: Add your the control notification handler code here
The 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))
{
The 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);
}
}
//the fill list
FillList (0);
AfxMessageBox (ListSaved. TXT the loaded! "" );
}

CodePudding user response:

Drop 1
flist. Close ();
//the fill list
FillList (0);
  • Related