how to get the lenth and offset of paragraph?

To All:

   I have a pragram ,here only is a example similar to My pragram ��

   these are some data :

    AAAA
       this is a test! here is the content
       of AAAA.
    BBBB
       this is a test,I want to know that
       between AAAA and BBBB lenth .
    CCCC
       this is a test! here how can I know
       CCCC excursion is what relative to
       AAAA��

best regards!
Terrcy





0
terrcy (22)
5/4/2004 3:15:21 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
842 Views

Similar Articles

[PageSpeed] 42

Application : SDI
View : Derived from CEditView.
Menu item added : Calculate Length

Paste paragraph mentioned in your mail in view.. be sure to remove any
leading blank spaces before 4 BBBB line...

Implementation of menu item..

void CEditViewView::OnCalclen()
{

 CEdit& edit = GetEditCtrl();

 CDC *pDC = edit.GetDC();

 TEXTMETRIC textmetric ;

 // textmetrices.. to get height of font
 pDC->GetTextMetrics( & textmetric ) ;

 // get the line .. the first one we want to refernce to...
 char szLine[1024] ;
 int nCharcopied = edit.GetLine( 0 , szLine , 1024 );

 // add null char... get line do not append null char...
 if( nCharcopied > 1023 )
  return;
 else
  szLine[nCharcopied] = '\0';



 CPoint pt1 , pt2 ;

 // get the position of First A
 if ( ! strcmp( szLine, "AAAA" ) )
  pt1 = edit.PosFromChar( 0 ) ;


 // get the line and character number
 int nChar = edit.CharFromPos( pt1 );

 // cross checking
 int nLineIndex = HIWORD(nChar);
    int nCharIndex = LOWORD(nChar);

 int nIndex = strlen ( szLine ) ;

 int nLineCount  = edit.GetLineCount() ;

 BOOL bFound = FALSE ;

 // iterate till we get desired line...
 for( int i = 1 ; i < nLineCount ; i++ )
 {
  ZeroMemory( szLine , 1024 );

  int nCharcopied = edit.GetLine( i , szLine , 1024 );

  if( nCharcopied > 1023 )
   return;
  else
   szLine[nCharcopied] = '\0';

  // get the desired line...
  if ( ! strcmp( szLine, "BBBB" ) )
  {
   nIndex++;

   pt2 = edit.PosFromChar( nIndex ) ;

   bFound = TRUE ;

   // we found it.. get out...
   break;
  }
  else
   // other wise add the length
   nIndex += strlen( szLine ) ;

 }

 if( bFound )
 {
  // add the font height.. so that end of A is reached...
  int BottomLine = pt1.y + textmetric.tmHeight ;

  // get the line and character number
  nChar = edit.CharFromPos( pt2 );

  // cross checking
  int nLineIndex = HIWORD(nChar);
  int nCharIndex = LOWORD(nChar);

  // add the height of the font since we are still referring to third line
  int TopLine = pt2.y  +  textmetric.tmHeight ;

  // just to make sure we are doing it right
  pDC->MoveTo( 10 , BottomLine );
  pDC->LineTo( 10 , TopLine );

  // so the total lenght difference between AAAA and BBBB is...

  int nDiff = TopLine - BottomLine ;

 }


}

If you want to see the line.. dont debug.. it will be erased because of app
behaviour ...

Neel

"terrcy" <terrcy@cn-finet.com> wrote in message
news:eoyKYYYMEHA.936@TK2MSFTNGP11.phx.gbl...
> To All:
>
>    I have a pragram ,here only is a example similar to My pragram ��
>
>    these are some data :
>
>     AAAA
>        this is a test! here is the content
>        of AAAA.
>     BBBB
>        this is a test,I want to know that
>        between AAAA and BBBB lenth .
>     CCCC
>        this is a test! here how can I know
>        CCCC excursion is what relative to
>        AAAA��
>
> best regards!
> Terrcy
>
>
>
>
>


0
neelagain (74)
5/4/2004 9:04:05 PM
Reply:

Similar Artilces: