Click here to Skip to main content
11,871,845 members (68,594 online)
Click here to Skip to main content
Add your own
alternative version

Stats

25.6K views
13 bookmarked
Posted

How to Implement Function TabbedTextOut() in WinCE

, 12 Dec 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
An article describing how to implement function TabbedTextOut() in WinCE

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.

void CeTabbedTextOut(HDC hDC,               // handle to DC
            int X,                          // x-coord of start
            int Y,                          // y-coord of start
            LPCTSTR lpString,               // character string
            int nCount,                     // number of characters
            int nTabPositions,              // number of tabs in array
            CONST LPINT lpnTabStopPositions,// array of tab positions
            int nTabOrigin                  // start of tab expansion
            )
{
	CString sTabString = lpString; 
	int nNextTabCharPos = sTabString.Find(L"\t");
	// if first tab character postion is not the start of tab expansion
	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)
	{
	    // set first tab character position as the start of tab expansion
		nTabOrigin = 0; 
	}
	// Initialize the rectangle in which the text is to be formatted
	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);
			// get the length of the remanent character string
			nCount = nCount - sTemp.GetLength(); 
		}
		// if there is no remanent character string 
		// or the character string doesn't contain tab characters 
		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];
		}
	}
	// writes the remanent character string that maybe contain tab characters
	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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rockone
Software Developer
China China
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151103.1 | Last Updated 13 Dec 2004
Article Copyright 2004 by Rockone
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid