如何实现RichEdit中数据的保存与载入?

lhb731 2006-07-21 11:02:23
如何时实现在RichEdit中用CRichEditCtrl::StreamOut把内容保存在一个缓存中,当用时再用CRichEditCtrl::StreamIn载入,RichEdit中的数据是有文件格式的文字(RTF)
...全文
408 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lincolnfz 2006-07-22
  • 打赏
  • 举报
回复
用这段代码,试下。

CString CAutoRichEditCtrl::GetRTF()
{
// Return the RTF string of the text in the control.
// Stream out here.
EDITSTREAM es;
es.dwError = 0;
es.pfnCallback = CBStreamOut; // Set the callback
CString sRTF = "";
es.dwCookie = (DWORD) &sRTF; // so sRTF receives the string
StreamOut(SF_RTF, es);
return sRTF;
}

//回调部分
DWORD CALLBACK CAutoRichEditCtrl::CBStreamOut(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
// Address of our string var is in psEntry
CString *psEntry = (CString*) dwCookie;
char tmp;
for (int i=0; i<cb; i++)
tmp = *(pbBuff+i);
///把数据存放在一个临时变量里
CString tmpEntry = "";
tmpEntry = (CString) pbBuff;
// And write it!!!
//把实际有效的数据返回
*psEntry += tmpEntry.Left(cb);
*pcb = cb;
return 0;
}
蒋晟 2006-07-21
  • 打赏
  • 举报
回复
IStream *pStream = NULL;
CreateStreamOnHGlobal( NULL, TRUE, &pStream);

sycnick 2006-07-21
  • 打赏
  • 举报
回复
MSDN的例子,保存到文件中,你修改一下,保存到缓存中就可以了,关键就是MyStreamOutCallback的回调

// My callback procedure that reads the rich edit control contents
// from a file.
static DWORD CALLBACK
MyStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CFile* pFile = (CFile*) dwCookie;

pFile->Write(pbBuff, cb);
*pcb = cb;

return 0;
}

// The example code.
// The pointer to my rich edit control.
extern CRichEditCtrl* pmyRichEditCtrl;
// The file to store the contents of the rich edit control.
CFile cFile(TEXT("myfile.rtf"), CFile::modeCreate|CFile::modeWrite);
EDITSTREAM es;

es.dwCookie = (DWORD) &cFile;
es.pfnCallback = MyStreamOutCallback;
pmyRichEditCtrl->StreamOut(SF_RTF, es);
lhb731 2006-07-21
  • 打赏
  • 举报
回复
具体是怎么一个过程,尤其那个回调函数我搞不懂
lhb731 2006-07-21
  • 打赏
  • 举报
回复
sycnick(李小虾) 可以说的再详细点不,谢谢
allenhiman 2006-07-21
  • 打赏
  • 举报
回复
齐达内

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧