Link to home
Start Free TrialLog in
Avatar of matthewsmith
matthewsmith

asked on

How do I scroll a CRichEditCtrl?

I have an output window implemented, similar to Visual Studio's.  Right now, I use LineScroll() to manually scroll the control one line at a time.  What I really want to do, is always output text at the end of the buffer, and have it automatically scroll when it hits the bottom of the screen - like a CRichEditView will do if you output text to it.  Is there a way to do this with CRichEditCtrl?

Thanks,
-Matt Smith
Avatar of chensu
chensu
Flag of Canada image

The following code works with an edit control. It should work with a rich edit control as well.

const int nLen = m_edit.GetWindowTextLength();
m_edit.SetSel(nLen, nLen);
m_edit.ReplaceSel(str);
Avatar of matthewsmith
matthewsmith

ASKER

This will output text at the end of the buffer, which is part of what I want to do, but it does not automatically scroll it, which I need to do.  And ideally, the scrolling would be set up so that you could scroll back the buffer, and when you 'let go' of the scroll thumb, it would snap back to the bottom, where current text is being output.  Is there a way to do that?

thanks,
-Matt
1. Try applying the ES_AUTOVSCROLL style.
2. Try calling LineScroll(numeric_limits<int>::max()) after ReplaceSel.
Applying the ES_AUTOVSCROLL doesn't seem to do anything special - it certainly doesn't allow the text to be auto-scrolled as the style implies.  Calling LineScroll(numeric_limits<int>::max()) will scroll the contents of the output window so that only the current line of output is shown at the very top of the window.  I want text to be output so that the current line is always output at the *bottom* of the screen, if you see what I mean.  I dealt with this by checking the line that's being output - if it contains a \n, I do a LineScroll(1).  This works reasonably well, except for a couple of things: If a line you output is longer than the window (I have word wrap turned off), A horizontal scroll bar will appear, which obscures the bottom line of text - you have to manually scroll down one line to see it.  The other problem is that if you scroll back in the buffer, you have to manually scroll back down to the bottom, and it's possible to scroll beyond the last line, so you have wacky problems like text being output in the middle of the screen.  Please let me know if that doesn't make sense.

thanks,
-Matt
I know what you mean. My example at CodeGuru does it exactly except that it uses an edit control instead of a rich edit control. I just found a sample at

http://www.codeguru.com/richedit/dalrichedit.shtml

Try it to see if it works like what you want.
None of these suggestions helped.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Chensu:
 
   Actually, the styles are ES_NOHIDESEL, and ES_AUTOVSCROLL (I know, I'm nitpicking).  This works though!  It was the ES_NOHIDESEL that I hadn't tried.  Many, Many thanks!!!

cheers,
-Matt