Solved

How to autoscroll a multiline edit box?

Posted on 1999-01-07
4
940 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

861 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

20 Experts available now in Live!

Get 1:1 Help Now