Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rich Edit Box scrolls past the last line of text.

Status
Not open for further replies.

sparafucile17

Programmer
Apr 5, 2002
40
US
Does anyone know why a Rich Edit box would scroll past the last line of text? What's happening in my program is that if the user clicks on the 'down arrow' of the vertical scroll bar, the Rich Edit box will scroll down past the last line of text until the last line of text is on the very top of the edit box.

Using the vertical 'scroll box' and not the arrows will not scroll past the last line of text. Which doesn't make much sense to me.

I'm trying to keep the edit box always scrolling when new text is added (i.e. a log) with SetWindowText(). But it seems like when I try to move the cursor with the LineScroll() function that it moves it past the end of the last line of text. (Similar to what's happening with the down arrow scroll button) I even tried offsetting the LineScroll like below:

main_log_ctrl->LineScroll((main_log_ctrl->GetLineCount() - 65), 0);

Assuming that there is 64 lines of text in my Edit Box. But of course, this did not work either.

Is there something that needs to be setup for Rich Edit Boxes? I must admit that I have never had much experience with Rich Edit's, so I am a little clueless.


Regards,
Jeff Tackett
Software Engineer

 
With RichEdit You should use ReplaceSel() to add new text on end of RichEdit, it works better:
long indE = pEdit->GetTextLength( );
pEdit->GetRichEditCtrl().SetSel( indE, indE );
pEdit->GetRichEditCtrl().ReplaceSel(pData, FALSE );
pEdit - Your CWnd*, pData - string to add.
 
Ok, I tried that but now I have effectively lost my 'logging' capability. Now when I ReplaceSel, I do not keep the old data. So what I thought to do was this:

main_log_ctrl->GetWindowText(buffer);
buffer += newString;
main_log_ctrl->SetSel(main_log_ctrl->GetTextLength(), 0);
main_log_ctrl->ReplaceSel(buffer, FALSE);

However, what happens for this case is that you see the Highlighted Selection being drawn and redrawn behind all of the text. Plus, the scroll bar is NOT moving to the last selection each time. Not to mention my original scroll past the last line problem is still there.

Any other suggestions?
 
Does anyone have suggestions on this topic? I've left this project for a while and recently I have returned to it. And of course, the same problem described above is still there.

Any help here?


Jeff
 
Once again...

Can anyone help me here? I need this problem fixed soon!!!

Jeff
 
sparafucile17,

well i also had this problem with my chat messenger program... but somehow managed to stop the scrolling past the last line when user clicks on the 'down arrow' of the vertical scroll bar....

wat u can do is add a message handler for EN_VSCROLL using ClassWizard and within that check whether you are on the last line or shud u enable user to scroll..... but i cudn't manage Horizontal Scroll Bar to stop going far off...

while adding text to the RichEdit Control instead of using SetWindowText itz better to use

GetWindowTextLength()
SetSel()
ReplaceSel()

once u do that u can then say

LineScroll(1) to scroll the added line...

hope that helps u....

regds

sridharan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top