怎样得到CRichEditCtrl的行高?

对于CRichEditCtrl, 如果每一行都是格式化好的字符串, 就是每一行的字符可能有多种格式,有的字符加粗,有的是11号字,有的是13号字,等等,我怎么去得到行高呢?或者是整个逻辑高度?

在http://www.pudn.com/downloads157/ebook/detail696696.html上找到一份代码,感谢陈启华同学。

int CRichEditCtrlEx::GetLineHeight(int LineNum) { int StartIndex = LineIndex(LineNum); int EndIndex = LineIndex(LineNum+1); if (EndIndex != -1) { CPoint LinePoint = GetCharPos(StartIndex); CPoint AfterPoint = GetCharPos(EndIndex); return (AfterPoint.y - LinePoint.y); } //CHARRANGE rage; //GetSel(rage); //CHARFORMAT2 charFormat; //charFormat.cbSize = sizeof(CHARFORMAT2); //charFormat.dwMask = CFM_SIZE; //long maxLineHeight = 0; //SetRedraw(FALSE); //for (long i=StartIndex;i<GetTextLength();i++) //{ // SetSel(i,i); // GetSelectionCharFormat(charFormat); // maxLineHeight = max(maxLineHeight,charFormat.yHeight/12+0.5); //} //SetSel(rage); //SetRedraw(); //return maxLineHeight; CString strLastLine; int len = GetTextLength(); GetTextRange(StartIndex, len, strLastLine); TRACE(_T("StartIndex=%d,EndIndex=%d,GetTextLength=%d,strLastLine=->%s<-/n"),StartIndex,EndIndex,len,strLastLine); if (strLastLine.IsEmpty()) { //if strLastLine there is nothing , if it do not return then the //bellow code will return the entire window height return 0; } CDC *pDC = GetDC(); // Get the page width and height from the screen. long lPageWidth = ::MulDiv(2000,1440, pDC->GetDeviceCaps(LOGPIXELSX)); long lPageHeight = ::MulDiv(2000,1440, pDC->GetDeviceCaps(LOGPIXELSY)); CRect rcPage(0, 0, lPageWidth, lPageHeight); FORMATRANGE Fr; Fr.hdc = NULL; Fr.hdcTarget = pDC->GetSafeHdc(); Fr.rc = rcPage; Fr.rcPage.left = Fr.rcPage.top = Fr.rcPage.right = Fr.rcPage.bottom = 0; Fr.chrg.cpMin = StartIndex; Fr.chrg.cpMax = EndIndex; FormatRange(&Fr, FALSE); FormatRange(NULL, FALSE); int newY = ::MulDiv(Fr.rc.bottom, pDC->GetDeviceCaps(LOGPIXELSY), 1440); ReleaseDC(pDC); return newY; } 

 

你可能感兴趣的:(null)