Expand Minimize
This topic has not yet been rated - Rate this topic

CRichEditCtrl::LineIndex

Retrieves the character index of a line within this CRichEditCtrl object.

int LineIndex( 
   int nLine = -1  
) const;
nLine

Contains the index value for the desired line in the text of the edit control, or contains –1. If nLine is –1, it specifies the current line, that is, the line that contains the caret.

The character index of the line specified in nLine or –1 if the specified line number is greater then the number of lines in the edit control.

The character index is the number of characters from the beginning of the rich edit control to the specified line.

For more information, see EM_LINEINDEX in the Windows SDK.

// The string for replacing.
LPCTSTR lpszmyString = _T("Hello, I'm the new second line.");

int nBegin, nEnd, nIndex;

// Replace the second line, if it exists, of the rich edit control 
// with the text lpszmyString.
nIndex = m_myRichEditCtrl.LineIndex(1);
if ((nBegin = nIndex) != -1)
{
   nEnd = nBegin + m_myRichEditCtrl.LineLength(nIndex); 
   m_myRichEditCtrl.SetSel(nBegin, nEnd);
   m_myRichEditCtrl.ReplaceSel(lpszmyString);
}   

Header: afxcmn.h

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.