DWORD CCEPEditView::MyStreamInCallback(DWORD dwCookie,LPBYTE pbBuff,LONG cb,LONG *pcb)
{
_CEP_EDITVIEW_* pCEPEditView = reinterpret_cast<_CEP_EDITVIEW_*>(dwCookie);
* pcb = pCEPEditView->pFile->Read(pbBuff, cb);
return 0;
}
DWORD CCEPEditView::MyStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
_CEP_EDITVIEW_* pCEPEditView = reinterpret_cast<_CEP_EDITVIEW_*>(dwCookie);
pCEPEditView->pFile->Write(pbBuff, cb);
*pcb = cb;
return 0;
}
void CCEPEditView::ShowStream(CString &strRtfData,BOOL isRtf)
{
CStringA strAnsiRtf(strRtfData);
if (strAnsiRtf.IsEmpty())
return;
m_isEnableUpdate = TRUE;
//AfxMessageBox(strRtfData);
CMemFile memTempFile(10240);
int nCount = strAnsiRtf.GetLength();
memTempFile.Write(strAnsiRtf.GetBuffer(nCount),nCount);
memTempFile.SeekTobegin
();
_CEP_EDITVIEW_ wndEditView;
wndEditView.pFile = &memTempFile;
wndEditView.pThis = this;
EDITSTREAM es;
es.dwCookie = reinterpret_cast<DWORD>( &wndEditView);
es.dwError = 0;
es.pfnCallback = MyStreamInCallback;
//m_pEditCtrl->SetWindowText(_T(""));
if (isRtf)
{
m_pEditCtrl->StreamIn(SF_RTF,es);
}
else
{
m_pEditCtrl->StreamIn(SF_TEXT,es);
}
m_isEnableUpdate = FALSE;
//m_pEditCtrl->StreamIn(SF_TEXT,es);
//m_pEditCtrl->StreamOut(SFF_SELECTION,es);
}
自己看吧。