Re: getting the rectangle occupied by line in CRichEditCtrl
Where do you get this error, at runtime or when you compile the project.
Does GetCharPos work? (they both give the same value)
Note that the code below assumes that you are using the same size character
all throught the edit control. If you change font name or font size in the
middle of the edit control then it will not work correctly.
AliR.
<harshalshete@gmail.com> wrote in message
news:1149166264.715336.315040@h76g2000cwa.googlegroups.com...
hi group,
i am able to get the line number from the caret position.
with something like this
CRichEditCtrl m_rich;
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;
int m_CurColumn = i - m_rich.LineIndex (m_CurLine-1) + 1;
but now i want to get the rectangle of this line for CRichEditCtrl
how i can do this?
because i read on codeproject a highlighting demo
but it is for CEditView
void CHiliteEditView::GetLineRect(int nLine, LPRECT lpRect) const
{
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->top + m_sizeChar.cy;
}
}
but PosFromChar is not supported by CRichEditCtrl because it gives
error "not a member function"
so how to do this
Thanks and Regards
Harshal shete