if (FileDlg.DoModal()==IDOK) { m_TxtFileName = FileDlg.GetPathName(); } else return;
OnReadout() ; // TODO: Add your control notification handler code here
}void CTTSPDlg::OnReadout() { CString sReadText; //Where the rich text will be streamed into
EDITSTREAM es;
es.dwCookie = (DWORD)&sReadText; // Pass a pointer to the CString to the callback function es.pfnCallback = MEditStreamOutCallback; // Specify the pointer to the callback function.
m_RichEdit.StreamOut(SF_TEXT, es); // Perform the streaming
// MessageBox(sReadText.Mid(0,500)); // Show you the first 500 chars of rich codes }
DWORD __stdcall MEditStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
extern CString m_TxtFileName;
CFile mFile;
CString sThisWrite;
sThisWrite.GetBufferSetLength(cb);
CString *psBuffer = (CString *)dwCookie;
for (int i=0; i<cb; i++) {
sThisWrite.SetAt(i, *(pbBuff+i));
}
*psBuffer += sThisWrite;
CString strTemp;
mFile.Open(m_TxtFileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
mFile.Write(sThisWrite, cb);
mFile.Flush();
mFile.Close();
AfxMessageBox("保存成功!");
*pcb = sThisWrite.GetLength();
sThisWrite.ReleaseBuffer();
return 0;
}void CTTSPDlg::OnBtnSaveinfo()
{
extern CString m_TxtFileName;
CString filt="txt File (*.txt)|*.txt|All files (*.*)|*.*||";
CFileDialog FileDlg(FALSE,"*.txt","*.txt",NULL,filt,this);
FileDlg.m_ofn.Flags|=OFN_FILEMUSTEXIST;
FileDlg.m_ofn.lpstrTitle="存储聊天内容";
if (FileDlg.DoModal()==IDOK)
{
m_TxtFileName = FileDlg.GetPathName();
}
else
return;
OnReadout() ; // TODO: Add your control notification handler code here
}void CTTSPDlg::OnReadout()
{
CString sReadText; //Where the rich text will be streamed into
EDITSTREAM es;
es.dwCookie = (DWORD)&sReadText; // Pass a pointer to the CString to the callback function
es.pfnCallback = MEditStreamOutCallback; // Specify the pointer to the callback function.
m_RichEdit.StreamOut(SF_TEXT, es); // Perform the streaming
// MessageBox(sReadText.Mid(0,500)); // Show you the first 500 chars of rich codes
}
CRichEdit::SaveFile
m_nWordWrap = WrapNone;
WrapChanged();
这两句。
若不行,你可以去了解一下archive类,就可以搞定了