Re: getting the rectangle occupied by line in CRichEditCtrl
hi AliR,
sorry for replying late,
i get this error at compile time.
as CharFromPos is not member function of CRichEditCtrl
and in MSDN it is shown as member function
steps i have followed
1)in my view class function HighLightLine i am i am changing my
caret position to specified line.
2)then i am calling drawcaret function
which will first of all try to get the rect associated with the line
but because i am using CRichEditCtrl i am not able to get the rect of
the line
next thing i want to do is by geting the rect i want create something
that will highlight it
and i am not changing the font of the rich edit in middle of the
application
so i think it won't be a problem.will it be?
so the code is as below.
i have view class as follow's
class CMyAppView : public CView
{
public:
CRichEditCtrl m_rich;
.
.//all other functions
// then i have function
void HighLightLine(CString Lineno);
void DrawCaret();
}
void CMyAppView::HighLightLine(CString lineno)
{
int nBegin;
int currentLineNumber;
int lineNumber = atoi( (LPCTSTR) lineno);
lineNumber -= 1;
if ((nBegin=m_rich.LineIndex(lineNumber))!= VAL_NEGATIVE_ONE)
{
currentLineNumber = m_rich.GetFirstVisibleLine();
m_rich.LineScroll(lineNumber - currentLineNumber-2);
int nEnd = m_rich.LineIndex( lineNumber + VAL_ONE );
m_rich.SetSel(nBegin, nBegin);
// To check line number means where the caret is present
long i, j;
CPoint p1, p2, pCaret;
m_rich.GetSel (i, j);
p1 = m_rich.GetCharPos (i);
p2 = m_rich.GetCharPos (j);
pCaret = m_rich.GetCaretPos ();
int m_CurLine = m_rich.LineFromChar (i) + 1;//current line
of caret
int m_CurColumn = i - m_rich.LineIndex (m_CurLine-1) + 1;
//the above thing is just for checking the caret position
is right
//or not
DrawCaretLine(m_CurLine);//call draw caret line with this
lineno.
}
void CMyAppView::DrawCaretLine(CString lineno)
{
CRect rect;
GetLineRect(m_nCaretLine, rect);
}
//this is for EditView i mean work well for CEditView Derived class
//i want to substitute it with CRichEditCtrl related code
void CMyAppView::GetLineRect(CString lineno)
{
if (nLine == 0) // the first line;
{
GetEditCtrl().GetRect(lpRect);
lpRect->bottom = lpRect->top + m_sizeChar.cy;
}
else if (nLine == GetEditCtrl().GetLineCount() - 1) // the last line
{
// we get previous line's rect, then offset it by one line height.
int nLineIndex = GetEditCtrl().LineIndex(nLine - 1);
CPoint ptPos = GetEditCtrl().PosFromChar(nLineIndex);
GetEditCtrl().GetRect(lpRect);
lpRect->top = ptPos.y;
lpRect->bottom = lpRect->top + m_sizeChar.cy;
OffsetRect(lpRect, 0, m_sizeChar.cy);
}
else // lines between first and last
{
int nLineIndex = GetEditCtrl().LineIndex(nLine);
CPoint ptPos = GetEditCtrl().PosFromChar(nLineIndex);
GetEditCtrl().GetRect(lpRect);
lpRect->top = ptPos.y;
lpRect->bottom = lpRect->to p + m_sizeChar.cy;
}
}
HOW TO DO IT?
if you can please tell me.
it will be helpfull for me..
if any suggetstion please tell me
Thanks and regards
Harshal shete