Solved

How to autoscroll a multiline edit box?

Posted on 1999-01-07
4
935 Views
Last Modified: 2013-12-04
I have implemented a modeless dialog box as an irc-style chat window for my network application (game).  I created it using vc++ 5.0 with MFC.  My current implementation is this...
When a new message is sent/received, I grab the text in the large multiline output box (main chat window), concatenate the new message to it in a temporary CString object, then set the edit box text to be the new, larger string.  Everything has been working perfectly except for the fact that when the text reaches the bottom of the main (read-only) edit box and the scroll bar kicks in (thanks MFC), the box doesn't automatically scroll down to reveal the latest text.  How do I make sure the box is always scrolled to the bottom when a new message comes in?
I guess my question is, how do I make a multiline edit box scroll down to the bottom within my code?

Oh...I have one more question.  I have noticed that my modeless dialog box is sort of "always on top" of the main window.  How do I make the main window appear over my modeless box when it's the active window?  Is this a result of my subclassing in the main app, or does this always happen by default?
0
Comment
Question by:smasher
  • 2
  • 2
4 Comments
 

Author Comment

by:smasher
ID: 1418270
Edited text of question
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1418271
You can send the edit box the EM_LINESCROLL message to scroll it so the last line is displayed.  

Let me know if you have any questions.
0
 

Author Comment

by:smasher
ID: 1418272
Ok that answer works, but now I have more of an annoyance than a problem.  I guess it's because of the way I handle the updating of the box (GetDlgItemText, add string in temp CString object, SetDlgItemText).  When I do SetDlgItemText, the box scrolls to the beginning automatically.  I then scroll down for as many lines as there are total messages (I didn't even think of handling messages that wrap to the next line...perhaps I'll not allow this).  This works, but there is sometimes a slight flicker as the box changes from the beginning to being scrolled to the end, and I would like to avoid this slight annoyance.  This usually only becomes very noticable in my tests of events that would probably not occur often (one user entering tens of blank messages per second), but happens nonetheless.
So I suppose I either need to change the way I handle updating the main window with text, or find a way to suppress the scrollback to the beginning when I call SetDlgItemText.  Is there any way to make the scrollbar "stick"?


Also, any ideas of the second part of my original question regarding my modeless dialog box being "always on top" of the main window, even when focus goes back to the main window?  Can I override the focus messages to handle this?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1418273
You can try using LockWindowUpdate() to prevent the edit control from flashing until you have repositioned the text.

It sounds like the modeless dialog box is owned by the main window.  Don't specify an owner (parent) when the dialog window is created and the problem should go away.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now