• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1101
  • Last Modified:

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
0
matthewsmith
Asked:
matthewsmith
  • 4
  • 4
1 Solution
 
chensuCommented:
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);
0
 
matthewsmithAuthor Commented:
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
0
 
chensuCommented:
1. Try applying the ES_AUTOVSCROLL style.
2. Try calling LineScroll(numeric_limits<int>::max()) after ReplaceSel.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
matthewsmithAuthor Commented:
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
0
 
chensuCommented:
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.
0
 
matthewsmithAuthor Commented:
None of these suggestions helped.
0
 
chensuCommented:
Try applying the EM_NOHIDESEL and EM_AUTOVSCROLL styles.
0
 
matthewsmithAuthor Commented:
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

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now