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;
}
// 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;