Solved

Autoscroll with RichEditCtrl...

Posted on 2003-12-12
6
369 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 63
Expand macro to ask for filename column 8 37
how to monitor remote shell execution on linux 9 100
firstChar challenge 13 115
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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