I need to format the
output text. It's easy to do this by using
function
TabbedTextOut()
in Win32 platform. But I have to implement this
function myself in
WinCE platform. And I named it
CeTabbedTextOut()
.
All input parameters are same to function
TabbedTextOut()
,
but function type is
void
,
not LONG
.
I know I did a lazy thing.
Collapse | Copy
Code
void CeTabbedTextOut(HDC hDC, int X, int Y, LPCTSTR lpString, int nCount, int nTabPositions, CONST LPINT lpnTabStopPositions, int nTabOrigin )
{
CString sTabString = lpString;
int nNextTabCharPos = sTabString.Find(L"\t");
if( nTabOrigin > 0)
{
int nTabCount = 0;
do{
nNextTabCharPos = sTabString.Find(L"\t", nNextTabCharPos+1);
nTabCount++;
if(nNextTabCharPos == -1)
break;
} while (nTabCount != nTabOrigin);
}
else if (nTabOrigin < 0)
{
nTabOrigin = 0;
}
RECT Rect;
Rect.left = X;
Rect.top = Y;
Rect.bottom = Rect.top + 20;
Rect.right = X + lpnTabStopPositions[nTabOrigin];
CString sTemp = _T("");
for(int i=nTabOrigin; i<nTabPositions; i++)
{
if( nNextTabCharPos != -1 )
{
sTemp = sTabString.Left(nNextTabCharPos+1);
sTabString = sTabString.Right(nCount - nNextTabCharPos-1);
DrawText(hDC, sTemp, sTemp.GetLength(), &Rect,
DT_EXPANDTABS | DT_NOCLIP);
nCount = nCount - sTemp.GetLength();
}
if(nCount == 0 || nNextTabCharPos == -1)
{
break;
}
nNextTabCharPos = sTabString.Find(L"\t");
Rect.left = X + lpnTabStopPositions[i];
if(i<nTabPositions-1)
{
Rect.right = X + lpnTabStopPositions[i+1];
}
}
if(nCount != 0)
{
ExtTextOut(hDC, Rect.left, Rect.top, 0, NULL,
sTabString, sTabString.GetLength(), NULL);
}
}
I know it's not a good
function, and any suggestion or tip is welcome.