通过CRichEditView::GetRichEditCtrl 得到CRichEditCtrl类型的变量引用 然后通过C的成员函数StreamOut就可将内容写到外部文件中,注意此函数的参数是一个EDITSTREAM型的变量,其中要指定一个回调函数 可以参考下面的例子。(摘自MSDN) // 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);//RTF格式可以保留排版格式
然后通过C的成员函数StreamOut就可将内容写到外部文件中,注意此函数的参数是一个EDITSTREAM型的变量,其中要指定一个回调函数
可以参考下面的例子。(摘自MSDN)
// 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);//RTF格式可以保留排版格式
除非我没试对
具体要求是要保存原有排版格式,而且要存成自定义的文件类型*.mips
通过定制
static DWORD CALLBACK MyStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CFile* pFile = (CFile*) dwCookie; pFile->Write(pbBuff, cb);
*pcb = cb; return 0;
}就可以实现自定义格式
我的是MDI,在MainFrm里有菜单事件处理函数OnSaveToTemp(),目的是把当前激活的子窗口里所显示的文本保存在temp.mips文件里并保持格式。
我的每个子窗口是一个上下的切分窗,上视图是基于CRichEditView的,用来显示code;下面是基于CListView的,用来显示编译出错的。其实整个程序就是要实现与VC++的编译环境类似的MIPS compiler。现在内核写好了就差界面,在compile时是通过把当前激活视图中的文本存在temp.mips文件中然后把该文件传给内核编译执行,但是我实在是不知道怎样实现保存,急啊!!!!!希望大侠指点,或者有什么别的实现方法也好,但要求是必须向内核传递程序代码文件才行。万分感谢!!!!!