Automatically scrolling an MFC Rich Edit Control(CRichEditCtrl)

by APIJunkie 13. November 2007 21:55

Some times it is convenient to use a Rich Edit Control as a scrolling text box. For example when using a Rich edit control as a log output window.

To do this we will need to do 2 things:

1. Make sure the selection in the Rich Edit Control is always visible.

You can change this Rich Edit Control property in both your resource editor and your code.

To do this in the resource editor you will need to set the "No hide selection" property of the Rich Edit Control to "true".

To do this in your code you can call the HideSelection Rich Edit Control member function:

// assuming CRichEditCtrl m_logCtrl; exists ...

 

// Show the selection and make it permanent

m_logCtrl.HideSelection(FALSE,TRUE);

2. Scroll the control to the last line of text by setting the selection to the last character in text.

To do this you can add the following code after updating the text you want to display:

// assuming CRichEditCtrl m_logCtrl; exists ...

long textLen = m_logCtrl.GetTextLength();

// set selection to last character...

m_logCtrl.SetSel(textLen-1,textLen-1);

Tags:

MFC | Win32

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



About the author

Name of author

My name is Bacon…James Bacon.

I am an API wars veteran. I was wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.