Solved

How to autoscroll a multiline edit box?

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

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…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…

810 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