Automatically scrolling an MFC Rich Edit Control(CRichEditCtrl)

by APIJunkie 11/13/2007 9:55:00 PM

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);

Currently rated 4.2 by 5 people

  • Currently 4.2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

MFC | Win32

Add comment


(Will show your Gravatar icon)  

  Country flag





Live preview

11/19/2008 9:36:35 PM

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

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. I am currently stuck in C++ and sniffing .NET.

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.

E-mail me Send mail


Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in