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;
}
}
{
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;
}
}
本文详细介绍了在CVFL对话框中如何使用CWnd类的DrawText函数绘制多行文本,包括文本长度检查、字符大小获取、布局调整等关键步骤。
2653

被折叠的 条评论
为什么被折叠?



