Solved

Autoscroll with RichEditCtrl...

Posted on 2003-12-12
6
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 114
dog bark java program 15 121
NotAlone Challenge 20 88
mapAB Challlenge 35 174
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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