Re: CRichEditCtrl contents from RTF file
Whoops! That went out sooner than I wanted... The above worked for
me, regardless of the file size, using unicode in project settings,
and using rtf in two rather distinctive languages.
I don't know why you use OnCreate. It should work, your code, but...
DDX_Control in DoDataExchange is easier.
Other than that, note a canonical form for any non-trivial
OnInitDialog is e.g:
bool CXDialog::OnInitDialog()
{
CDialog::OnInitDialog();
TRY
{
InitBabyInit();
}
CATCH(CException* pe)
{
ReportErrorSomehow(pe);
EndDialog(PROBABLY_ID_CANCEL); // But it's up to you.
}
}
It's a bad idea to let exception escape your callback (possible due to
use of MFC in it), so you should e.g. do:
struct RichEditStreamInContext
{
RichEditStreamInContext(const CString& csFileName) :
m_File(csFileName, CFile::modeRead), m_pError(NULL) {}
CFile m_File;
CException* m_pError;
};
static DWORD CALLBACK MyStreamInCallback(DWORD_PTR dwCookie, LPBYTE
pbBuff, LONG cb, LONG *pcb)
{
RichEditStreamInContext& Ctx =
*reinterpret_cast<RichEditStreamInContext*>(dwCookie);
try
{
*pcb = Ctx.m_File.Read(pbBuff, cb);
return 0;
}
catch (CException* p)
{
ASSERT(FALSE);
Ctx.m_pError = p;
return -1;
}
}
and in OnInitDialog:
....
RichEditStreamInContext Ctx(RTF_PATH_HERE);
EDITSTREAM es = { (DWORD_PTR)&Ctx, 0, &MyStreamInCallback };
MCALLBACK)MyStreamInCallback;
m_Edit.StreamIn(SF_RTF, es);
if (es.dwError)
HandleError(Ctx); // Including looking at Ctx.m_pError;
HTH,
Goran.