gpt4 book ai didi

c++ - MFC。保存和加载 CMFCRibbonRichEditCtrl

转载 作者:太空宇宙 更新时间:2023-11-04 13:18:30 25 4
gpt4 key购买 nike

我正在寻找匹配项并用颜色突出显示它们。在此之后我只显示它们。我需要用突出显示的词重新显示整个文本。我试图通过 std::stringstreamStreamIn + 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;
}

最佳答案

我仍然找到了解决方案,但使用的是 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;
}

关于c++ - MFC。保存和加载 CMFCRibbonRichEditCtrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36259665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com