areams
asked on
Add text to cedit without scrolling
I have a ceditview that has text continually added to the end(1 line of text at a time). Well I would like to disable the scrolling when the last line of the edit control is not in view but still add the text to the end. I noticed SetSel has a no scroll flag, but it's too bad ReplaceSel doesn't.
Does anyone know a way to accomplish this?
-Thankx
Does anyone know a way to accomplish this?
-Thankx
ASKER
Thanks for the quick response but unfortunately this causes the same problem except in the opposite direction. This now causes the scroll bar to "fight" it's way to the very top position each time a line of text is added as opposed to the bottom. I had considered this method before but I assumed it would produce too much flicker. I need the edit control and scrollbar to maintain the exact same position if the last line is not visible(although scroll bar slider should shrink as more text is added). Any more suggestions or am I doing something wrong? Thanks again.
Flicker, that's an easy one...
Before the call, add an extra line:
SetRedraw( FALSE );
GetSel
SetWindowText
SetSel
SetRedraw( TRUE );
Phillip
Before the call, add an extra line:
SetRedraw( FALSE );
GetSel
SetWindowText
SetSel
SetRedraw( TRUE );
Phillip
ASKER
Thanks, that helped with the flicker. now if only that scrollbar slider would stay put...
Turn off the scroll bar slider as well! It's a window too!
Phillip
Phillip
When u add a text to edit control or view, there are two situations:
1) Your edit control or view has the focus: In this case the scroll bar scrolls to the last line added.
2) the edit ctrl or view doesn't have focus: In this case the scroll bar retains its position and just shrinks in size.
Now you need to remove the focus from your credit view and then call SetSel and ReplaceSel
HWND hWnd = ::SetFocus(NULL);
// Instead of NULL if you some hWnd (other than Credit view)
// where u can set the focus, u can use that
//Now here u call SetSel and ReplaceSel
// put the focus back to the original window
::SetFocus(hWnd);
I hope this solves your problem.
Regards,
Rakesh
1) Your edit control or view has the focus: In this case the scroll bar scrolls to the last line added.
2) the edit ctrl or view doesn't have focus: In this case the scroll bar retains its position and just shrinks in size.
Now you need to remove the focus from your credit view and then call SetSel and ReplaceSel
HWND hWnd = ::SetFocus(NULL);
// Instead of NULL if you some hWnd (other than Credit view)
// where u can set the focus, u can use that
//Now here u call SetSel and ReplaceSel
// put the focus back to the original window
::SetFocus(hWnd);
I hope this solves your problem.
Regards,
Rakesh
ASKER
I tried to set the focus to NULL and to the mainframe but I couldn't seem to get it to work. I have also tried disabling the scrollbar using EnableScrollBarCtrl but unfortunately ReplaceSel just reenables it. Thanks though...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Its not what I wanted to hear but thats the way things go. I am working on my own control now. Thanks Mike and everyone else who contributed!
-Aaron
-Aaron
Use SetWindowText to set the new text (GetWindowText gives you the old text)
Use SetSel to put the cursor where you want (e.g. back to the old pos)