Autoscroll with RichEditCtrl...

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
LVL 4
James AtkinSenior Principle Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

James AtkinSenior Principle Software EngineerAuthor Commented:
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
rushinmonkeyCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James AtkinSenior Principle Software EngineerAuthor Commented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

James AtkinSenior Principle Software EngineerAuthor Commented:
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
rushinmonkeyCommented:
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
James AtkinSenior Principle Software EngineerAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.