Jump to content
  • Advertisement
Sign in to follow this  
Zmurf

(Solved) Making a Rich Text Box Scroll to the Appened Text

This topic is 4859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can I get my Rich Text Box to automatically scroll down the the text i've just appened to it. Whenever I appened text to it and the text is below the visible text area it just stays there and you have to manual scroll dow nto see it. I tried richTextBox->ScrollToCaret, but I can't figure out how to make the caret move to the end of the text in the box. Any ideas? [Edited by - Zmurf on July 27, 2005 6:09:36 AM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I'm not sure if this will work for you, but I used this with a normal edit control and sorry I am not at home to glance at the SDK Documentation but this is what I have for appending text to the end and having it show:



SendMessage( hEditControl, EM_LINESCROLL, 0,
(LPARAM)(int)(SendMessage(hEditControl, EM_GETLINECOUNT, 0, 0) - 1) );



hEditControl is the handle of the edit(rich edit in your case) control.


-David

Share this post


Link to post
Share on other sites
This works for me:


// Scroll to the bottom
SendMessage(m_richEdit, WM_VSCROLL, SB_BOTTOM, 0);

// Set the caret to the bottom of control and scroll to it
SendMessage(m_richEdit, EM_SETSEL, std::numeric_limits<int>::max(), std::numeric_limits<int>::max());
SendMessage(m_richEdit, EM_SCROLLCARET, 0, 0);

Share this post


Link to post
Share on other sites
I'm using Visual Studio .Net, I implemented the code, and I'm getting new errors that are totally irelevant to the code I added, there not even in the same document. ><

Quote:
c:\Documents and Settings\Zmurf\My Documents\Visual Studio\Projects\Sticky\frmConnect.h(292) : error C2039: 'GetObjectA' : is not a member of 'System::Resources::ResourceManager'
stdafx.cpp(0) : see declaration of 'System::Resources::ResourceManager'
initSticky.cpp(6) : error C2731: 'WinMain' : function cannot be overloaded
initSticky.cpp(6) : see declaration of 'WinMain'
frmMain.cpp
c:\Documents and Settings\Zmurf\My Documents\Visual Studio\Projects\Sticky\frmConnect.h(292) : error C2039: 'GetObjectA' : is not a member of 'System::Resources::ResourceManager'
stdafx.cpp(0) : see declaration of 'System::Resources::ResourceManager'


Is it an MFC command? Bacause I don't use MFC (I don't think I'm going to learn either)

Share this post


Link to post
Share on other sites
Chances are you included <windows.h> (along with frmConnect.h), which is now defining:

WINGDIAPI int WINAPI GetObjectA( IN HGDIOBJ, IN int, OUT LPVOID);
#ifdef UNICODE
#define GetObject GetObjectW
#else
#define GetObject GetObjectA
#endif // !UNICODE

So it effectively takes over the name "GetObject" and replaces it with GetObjectA or GetObjectW, making the compiler confused when it sees your own GetObject method. I'm sure you can see this is very annoying :). Perhaps you could rename your GetObject method in frmConnect.h to something else?

And no, this is plain Win32 API, not using the MFC.

Share this post


Link to post
Share on other sites
Lol, see this is what I don't understand. I haven't used a GetObject command in my application! I'm still fairly new to Visual Studio and Windows Forms programming, and this is the biggest project I've made so far.

I've gone to the help files and I've included <windows.h> and linked 'User32.lib' because it said they were dependencies and I still get these errors.

Share this post


Link to post
Share on other sites
Oh, you're using Windows Forms? Sorry, I assumed it was using the plain Win32 API.
I'm not sure about how to fix this problem in Winforms - the code I gave probably won't work :)

Share this post


Link to post
Share on other sites
The way I've always done it is set the caret using richTextBox.SelStart = richTextBox.Text.Length , and then use ScrollToCaret.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!