Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add text to cedit without scrolling

Posted on 1998-10-22
9
Medium Priority
?
1,019 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:areams
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1323712
Use GetSel to get the old pos

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

Author Comment

by:areams
ID: 1323713
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.
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1323714
Flicker, that's an easy one...

Before the call, add an extra line:

SetRedraw( FALSE );

GetSel
SetWindowText
SetSel

SetRedraw( TRUE );

Phillip
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:areams
ID: 1323715
Thanks, that helped with the flicker.  now if only that scrollbar slider would stay put...
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1323716
Turn off the scroll bar slider as well!  It's a window too!

Phillip
0
 

Expert Comment

by:rakeshkalra
ID: 1323717
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
0
 

Author Comment

by:areams
ID: 1323718
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...
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 600 total points
ID: 1323719
You can't avoid the scroll bar moving.  The scroll bar will resize, because the content of the window is growing.  The scroll bar has to show the relative size of the information in the window.

The scroll bar will also move towards the top of the window (if you're adding text at the end) beause the relative position of the current view is changing, too. It's becoming closer to the beginning of the control with more data in the control.

Think of a scroll bar that's 100 pixels high. If you're looking at line 20, and there's 50 lines in the control, your scroll bar should be at (20/50)*100, which is 40.  If you add 50 lines, the scroll bar needs to start at (20/100)*100, which is 20.  The ratio changes because you're adding text!

You're asking for the impossible. You can minimize the repainting the way other folks here have told you to. You can hack around with the control to try to set the scroll info yourself to make the control not resize or move the bar.  That might work, but it breaks the Windows user interface (which says that the scroll bar should show the relative range and position).  If you really must have it your way, you'll need to write your own control.

B ekiM

0
 

Author Comment

by:areams
ID: 1323720
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question