Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to scroll CRichEditCtrl

450 views
Skip to first unread message

Anton Korenev

unread,
Aug 11, 1999, 3:00:00 AM8/11/99
to
Hello:
Can anybody help me to scroll CRichEditCtrl so that I when I add text to
control
it scrolls so that last added line is always visible at the bottom?...

I'm trying to something like Output window in VC++ IDE: when you compile you
program,
in Output window you see status and text is automaticall scrolled up.

The only scrolling function LineScroll() works strange way. In order to do
what I want,
I can call LineScroll(1) just when number of lines in control exceeds
maximum visible
number of lines. But how then to determine max number of visible lines in
control?...

thanks in advance!!!

anton

Kurt Grittner

unread,
Aug 12, 1999, 3:00:00 AM8/12/99
to
Hi Anton,

void CTermView::DisplayRaw(LPCSTR pstr)
{
// Display characters without vsprintf-formatting
long nStart;
long nEnd;

CRichEditCtrl& ed = GetRichEditCtrl();
// Is the edit control almost full?
CheckTermFull();

// Write text to string and append to edit control
nStart = ed.GetTextLength();
ed.SetSel(-1,-1);
ed.ReplaceSel(pstr);
nEnd = ed.GetTextLength();
ed.SetSel(-1,-1);
}

void CTermView::CheckTermFull()
{
CRichEditCtrl& ed = GetRichEditCtrl();

if (ed.GetLineCount() > m_MaxLines)
{
// We have more lines than we wanted in scroll back
buffer
// Count number of lines to get rid of
int KillLines = ed.GetLineCount() - m_MaxLines;

// Only kill 25 lines at a time to reduce screen jump
if (KillLines > 24) {
// Find the location for that line
char szBuf[2];
if (m_bRedraw) {
// Avoid screen jump during history
shrink
SetRedraw(FALSE);
}
int iEndSel = ed.LineIndex(KillLines);
// Select from start of text to start of that
line
ed.SetSel(0,iEndSel);
// NULL text
szBuf[0] = '\0';
// Replace selection with nothing
ed.ReplaceSel(szBuf);
if (m_bRedraw) {
SetRedraw(TRUE);
}
}
}

}

Hope this helps,
Kurt

Mat Kramer

unread,
Aug 12, 1999, 3:00:00 AM8/12/99
to
Not sure, but SetSel(-1, -1) may do the trick. It seems to work for me, but
I always do a ReplaceSel() after that.

Anton Korenev wrote in message <#F71YxC5#GA.205@cppssbbsa04>...

Bob Cozzi

unread,
Aug 12, 1999, 3:00:00 AM8/12/99
to
When ever you do a SetSel() to a location, that location usually scrolls
into view, unless you've done something to stop that from happening. So just
set the select to the starting position in the control and that location
should scroll visible.

I have to say, the more I use RichEdit, the more I wish I would have written
my own rich edit-like control. It just doesn't do much. Remember, MS Word
does not use the RichEdit control, but rather it uses the Text Object Model,
as does the Visual Studio/C++editor. So they have some control over things
that are NOT exposed in the RichEdit control.

I've been working for months trying to get at the ITextDocument of a
RichEdit control, but can't seem to get there. Even my "friends" at
Microsoft just don't know what to do--apparently that stuff gets coded in
the mythical back room and magically appears for them to use when they need
it. They actually suggested that I use the MS HTML control instead since
that thing is being supported/developed more so than RichEdit. ;-(

--

Bob Cozzi
www.rpgiv.com


Anton Korenev <an...@korenev.com> wrote in message
news:#F71YxC5#GA.205@cppssbbsa04...
> Hello:


> Can anybody help me to scroll CRichEditCtrl so that I when I add text to
> control
> it scrolls so that last added line is always visible at the bottom?...
>

0 new messages