Solved

Autoscroll with RichEditCtrl...

Posted on 2003-12-12
6
367 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
ID: 9928894
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
ID: 9940605
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
ID: 9940719
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:jatkin
ID: 9941408
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
ID: 9941913
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
ID: 9948169
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Importing Special Characters in Dynamics GP Through Integration Manager 3 69
sumDigits challenge 9 120
haveThree challenge 22 112
tripleUp challenge 7 73
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 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

11 Experts available now in Live!

Get 1:1 Help Now