Sometimes Content in CRichEditCtrl Does not Show up properly!

I am trying to use a read-only CRichEditCtrl to display information.

What is boring me is to scroll the content to the last part.

As shown below, the content comes from CRunNotes object m_lpRunNotes.

The run note class is a container to store run notes, which is defined by run time (difference of timeGetTime()) and text note (CString).

The RTF content is stream-ined to the rich edit control.

I tried to input run note with "Run Note n", where n = 1, 2, 3, ...,
The RTF content for each run note is 3 lines.

When the fourth note was added to the CRunNotes object, the content does not appear in the rich edit control. Click the scrollbar will make it visible.

When 5th run note is added, the 5th note is shown from the top. And 6th note is OK. Again, when 7th note is added, no content is visible. Same thing, clicking the scrollbar will make it visible.

void CRunNoteDlg::DisplayPreviousRunNotes()
{
CString strRTFNotes = m_lpRunNotes->GetRTFNotes();
if (!strRTFNotes.IsEmpty())
{
EDITSTREAM es = { (DWORD)&strRTFNotes, 0, EditStreamCallBack};
m_PrevNotesCtrl.StreamIn(SF_RTF, es);
}

int nLineCount = m_PrevNotesCtrl.GetLineCount();
TRACE1("Number of Lines = %d\n", nLineCount);
m_PrevNotesCtrl.LineScroll(nLineCount - 5);
m_PrevNotesCtrl.UpdateWindow();
/*
SCROLLINFO ScrollInfo;
if (m_PrevNotesCtrl.GetScrollInfo(SB_VERT, &ScrollInfo))
{
// m_PrevNotesCtrl.SetScrollPos(SB_VERT, ScrollInfo.nMax);
int nLineCount = m_PrevNotesCtrl.GetLineCount();
TRACE1("Number of Lines = %d\n", nLineCount);
m_PrevNotesCtrl.LineScroll(nLineCount - 5);
m_PrevNotesCtrl.UpdateWindow();
}
*/
}

DWORD CALLBACK CRunNoteDlg::EditStreamCallBack(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CString *pstr = (CString*)dwCookie;

int cbStr = pstr->GetLength();

if (cbStr < cb)
{
*pcb = cbStr;
memcpy(pbBuff, (LPCSTR)*pstr, cbStr);
pstr->Empty();
}
else
{
*pcb = cb;
memcpy(pbBuff, (LPCSTR)*pstr, *pcb);
*pstr = pstr->Right(cbStr - cb);
}
return 0;
}

By the way, the control can display 7 lines without scroll.

Initially I used a edit control to display the run note information. I works to scroll to the last part! Of course, in that case, we can use SetWindowText to update the run notes.
[2518 byte] By [dianjiang] at [2007-11-19 7:22:13]