我正在寻找比赛并用彩色突出显示它们。
在此之后我只显示它们。
我需要用突出显示的单词重新显示整个文本。
我尝试通过std::stringstream
和StreamIn
+ StreamOut
进行操作,但颜色丢失了。
void RichText::saveInStringstream()
{
EDITSTREAM es = { 0, 0, editStreamOutCallback };
es.dwCookie = reinterpret_cast<DWORD_PTR>(&m_rtf);
m_richEdit.StreamOut(SF_RTF, es);
}
DWORD CALLBACK RichText::editStreamOutCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
std::stringstream *rtf = reinterpret_cast<std::stringstream *>(dwCookie);
rtf->write(reinterpret_cast<char *>(pbBuff), cb);
*pcb = cb;
return 0;
}
答案 0 :(得分:0)
我仍然使用CMemFile
找到了解决方案。
void RichStream::Save(CMFCRibbonRichEditCtrl &richEdit)
{
file.SeekToBegin();
EDITSTREAM es = { 0, 0, editStreamOutCallback };
es.dwCookie = reinterpret_cast<DWORD_PTR>(&file);
richEdit.StreamOut(SF_RTF, es);
}
void RichStream::Load(CMFCRibbonRichEditCtrl &richEdit)
{
file.SeekToBegin();
EDITSTREAM es = { 0, 0, editStreamInCallback };
es.dwCookie = reinterpret_cast<DWORD_PTR>(&file);
richEdit.StreamIn(SF_RTF, es);
}
DWORD CALLBACK RichStream::editStreamOutCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CMemFile* pFile = (CMemFile*)dwCookie;
pFile->Write(pbBuff, cb);
*pcb = cb;
return 0;
}
DWORD CALLBACK RichStream::editStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CMemFile* pFile = (CMemFile*)dwCookie;
*pcb = pFile->Read(pbBuff, cb);
return 0;
}