Re: how can i get the height of a line in a richeditctrl
Thinking about your problem this morning I came up with this
//LineNum is the zero based index of the line you want to measure
int GetLineHeight(CRichEditCtrl *pEdit,int LineNum)
{
if (pEdit == NULL || pEdit->GetSafeHwnd() == NULL)
{
return -1;
}
int StartIndex = pEdit->LineIndex(LineNum);
int EndIndex = pEdit->LineIndex(LineNum+1);
if (EndIndex == -1)
{
EndIndex = pEdit->GetTextLength() - 1;
}
if (StartIndex == EndIndex)
{
return -1;
}
CDC *DC = pEdit->GetDC();
// Get the page width and height from the screen.
int X = 0;
int Y = 0;
int X2 = ::MulDiv(2000,1440, DC->GetDeviceCaps(LOGPIXELSX));
int Y2 = ::MulDiv(2000,1440, DC->GetDeviceCaps(LOGPIXELSY));
CRect rcPage(X,Y,X2,Y2);
FORMATRANGE Fr;
Fr.hdc = NULL;
Fr.hdcTarget = DC->m_hDC;
Fr.rc = rcPage;
Fr.rcPage.left = Fr.rcPage.top = Fr.rcPage.right = Fr.rcPage.bottom = 0;
Fr.chrg.cpMin = StartIndex;
Fr.chrg.cpMax = EndIndex;
pEdit->FormatRange(&Fr,FALSE);
pEdit->FormatRange(NULL,FALSE);
int NewY = ::MulDiv(Fr.rc.bottom,DC->GetDeviceCaps(LOGPIXELSY),1440);
pEdit->ReleaseDC(DC);
return NewY;
}
"Sunny" <sound_of_nature@hotmail.com> wrote in message
news:O4krmL%235IHA.3684@TK2MSFTNGP05.phx.gbl...
Hi "Joseph M. Newcomer" ,
I don't know how to iterate over all the characters of the
line. do you have some code to do this?
thanks very much.