Solved

Autoscroll with RichEditCtrl...

Posted on 2003-12-12
6
362 Views
Last Modified: 2013-11-20
Hi,

I have an application that uses a class based on the RichEditCtrl ...

When I use this on a Windows 2000 machine, whenever text is added to the RTF, the last line of the RTF contents is always displayed at the bottom of the RTF object (i.e. it autoscrolls when required).  Running the same app on an NT4 box does not scroll at all!

I have tried adding LineScroll(1); to the last line where the text is added to the RTF contents.  This has no effect on the Win2k box (scroll works as expected) but the NT box now scrolls a little more than expected!!!  Gradually, as each line is added, the last viewable line moves up the object, until it is the only visible info!!!

Any ideas as to what is going on?????

Best regards,

James
0
Comment
Question by:jatkin
  • 4
  • 2
6 Comments
 
LVL 4

Author Comment

by:jatkin
Comment Utility
Also,

I try to set the alignment using
   pf.wAlignment = PFA_LEFT  (or PFA_RIGHT or PFA_CENTER)

And it always aligns to the left - I change the Tab indent in the same command as I set the Alignment and that works ok so I guess the SetParaFormat(pf) appears to be working.  I have set the Mask in the following manner:
   pf.dwMask = PFM_ALIGNMENT | PFM_TABSTOPS

This code again works fine on Win2k, but not NT !!!!!  

Going slowly insane,

James
0
 
LVL 1

Accepted Solution

by:
rushinmonkey earned 50 total points
Comment Utility
here is how to scroll the richedit - m_edCons

CRect rectClient;
MyRichEdit.GetClientRect(&rectClient);

// get the number of lines
int nLines = MyRichEdit.GetLineCount();

// get the char index of the 1st char of last line
int nLineIndex = MyRichEdit.LineIndex(nLines - 1);

// sets the position of that character in the control
CPoint pointPos = MyRichEdit.GetCharPos(nLineIndex);
      
// scroll down a line and see if the char is now in control
while (!rectClient.PtInRect(pointPos))
{
      MyRichEdit.LineScroll(1);
      pointPos = MyRichEdit.GetCharPos(nLineIndex);
}
MyRichEdit.LineScroll(1);
///////////////////////////////////////////////////////////

can u tell me how you are doing tab indents? I didn't realise u could...
0
 
LVL 4

Author Comment

by:jatkin
Comment Utility
Ok, that has sorted out the scrolling quite nicely - why doesn't NT4 behave as well as 2000!!!!

As for tabs, I use the Paragraph formatting to set the various indents using
  pf.rgxTabs[x]

Then, providing we are at the beginning of a line, depending on the required tabstop, simply prefix the text with the appropriate no of '\t'...  

It's not the best way of doing it, but it works well enough for my current needs...

Any ideas about the strange behaviour (or rather lack of) for the Alignment???

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Author Comment

by:jatkin
Comment Utility
I've just opened the RTF file generated on the NT4 machine in Wordpad (on the same machine) and the Left, Right & Center formatting are there!  It appears to be related to the MFC based class not Displaying the justified text!  

Do you know of a property I need to configure to ensure that the text justification is displayed??

Thanks,

James
0
 
LVL 1

Expert Comment

by:rushinmonkey
Comment Utility
dont know if it helps but I am streaming RTF in and out of my richedit like this:

CString CRichEditEx::GetRTF()
{
      // Return the RTF string of the text in the control.
      
      // Stream out here.
      EDITSTREAM es;
      es.dwError = 0;
      es.pfnCallback = CBStreamOut; // Set the callback
      CString sRTF = "";
      es.dwCookie = (DWORD) &sRTF; // so sRTF receives the string
      StreamOut(SF_RTFNOOBJS, es); // Call CRichEditCtrl::StreamOut to get the string.

      return sRTF;
}
/////////////////////////////////////////////////////////////////////////////


void CRichEditEx::SetRTF(CString sRTF)
{
      // Put the RTF string sRTF into the rich edit control.
      //      SetSel(-1,-1);
      // Read the text in
      EDITSTREAM es;
      es.dwError = 0;
      es.pfnCallback = CBStreamIn;
      es.dwCookie = (DWORD) &sRTF;
      StreamIn(SF_RTF|SFF_SELECTION, es);      // Do it.
}
/////////////////////////////////////////////////////////////////////////////

// Callback function to stream an RTF string into the rich edit control.
DWORD CALLBACK CRichEditEx::CBStreamIn(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
//      This function taken from CodeGuru.com
//      http://www.codeguru.com/richedit/rtf_string_streamin.shtml
//      Zafir Anjum

      CString *pstr = (CString *) dwCookie;

      if (pstr->GetLength() < cb)
      {
            *pcb = pstr->GetLength();
            memcpy(pbBuff, (LPCSTR) *pstr, *pcb);
            pstr->Empty();
      }
      else
      {
            *pcb = cb;
            memcpy(pbBuff, (LPCSTR) *pstr, *pcb);
            *pstr = pstr->Right(pstr->GetLength() - cb);
      }

      return 0;
}
/////////////////////////////////////////////////////////////////////////////


// Callback function to stream the RTF string out of the rich edit control.
DWORD CALLBACK CRichEditEx::CBStreamOut(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
      // Address of our string var is in psEntry
      CString *psEntry = (CString*) dwCookie;
      
      CString tmpEntry = "";
      tmpEntry = (CString) pbBuff;

      // write it
      *psEntry += tmpEntry.Left(cb);
      return 0;
}
/////////////////////////////////////////////////////////////////////////////


thanks for the tabs thing, its helped alot..

rushin
0
 
LVL 4

Author Comment

by:jatkin
Comment Utility
Hi,

I'll accept the comments regarding the Autoscroll as the answer as this has fixed my main issue nicely.

I'll take a look at the streaming of text to the class and see if it fixes the other issue...

Thanks again for the help,

James
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
if loop error 4 76
cat dog challenge 18 122
bigDiff challenge 17 74
NotAlone Challenge 20 70
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

8 Experts available now in Live!

Get 1:1 Help Now