DrawText显示多行文本并能控制行距

来源:互联网 发布:linux 免驱动无线网卡 编辑:程序博客网 时间:2024/04/30 00:37
void CVFLDlg::DrawMultLineText(CDC *pDC, CRect rect, int nRowDis, UINT nFromat, CString strText)
{

if( strText.GetLength() <= 0 )
return;

WCHAR* pText = strText.GetBuffer(strText.GetLength());
int nCount = strText.GetLength();
CRect rtChar;
CSize size = pDC->GetTextExtent(pText + 0, 1);
int nRowHeight = size.cy + 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;
}
}
原创粉丝点击