Solved

How to autoscroll a multiline edit box?

Posted on 1999-01-07
4
984 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
[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
  • 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

622 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