自定义行间距 多行输出 解决DrawText 无法自定义行间距的问题

来源:互联网 发布:人人商城数据库表 编辑:程序博客网 时间:2024/05/18 00:27
//nRowDis 行间距  strText 输出内容 
void DrawMultLineText(CDC* pDC ,CRect rect, int nRowDis, UINT nFromat, CString strText) {if( strText.GetLength() <= 0 )return;WCHAR* pText = strText.GetBuffer();int nCount = strText.GetLength();CRect rtChar;CSize size = pDC->GetTextExtent(pText + 0, 1);int nRowHeight = size.cx + nRowDis;rtChar.top = rect.top;rtChar.left = rect.left;rtChar.bottom= rtChar.top + nRowDis + size.cy;rtChar.right= rtChar.left + size.cx;CString strChar;for (int nCharIndex = 0; nCharIndex < nCount; nCharIndex++){if( rtChar.right > rect.right ){rtChar.top = rtChar.bottom;rtChar.bottom += nRowHeight;size = pDC->GetTextExtent(pText + nCharIndex, 1);rtChar.left = rect.left;rtChar.right = rtChar.left + size.cx;if( rtChar.bottom > rect.bottom )break;}strChar = pText[nCharIndex];pDC->DrawText(strChar, rtChar, nFromat);size = pDC->GetTextExtent(pText + nCharIndex + 1, 1);rtChar.left = rtChar.right;rtChar.right += size.cx;}} 

多行文本 自定义 行间距