⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawtextex.cpp

📁 基于WINDOWS mobile 的用于创建一个窗体和自定义试图的工程
💻 CPP
字号:


#include "StdAfx.h"

#include "DrawTextEx.h"


//
// The UNICODE ellipsis character
//
#define ELLIPSIS ((TCHAR)0x2026)


// DrawTextEx
//
//		Extended version of DrawText
//
int DrawTextEx(HDC hDC, LPCTSTR lpString, int nCount, LPRECT lpRect, UINT uFormat)
{
	//
	// Check if the user wants to use the end ellipsis style
	//
	if(uFormat & (DT_END_ELLIPSIS | DT_MODIFYSTRING))
	{
		SIZE	szStr;
		LPTSTR	lpStr	= (LPTSTR)lpString;				// Make it non-const
		int		nWidth	= lpRect->right - lpRect->left;	// Rect width

		//
		// If the user did not specify a string length,
		// calculate it now.
		//
		if(nCount == -1)
			nCount = _tcslen(lpStr);

		//
		// Check if the text extent is larger than the rect's width
		//
		GetTextExtentPoint32(hDC, lpStr, nCount, &szStr);
		if(szStr.cx > nWidth)
		{
			//
			// Make a worst-case assumption on the char count
			//
			int nEstimate = (nCount * nWidth) / szStr.cx + 1;

			if(nEstimate < nCount)
				nCount = nEstimate;

			//
			// Insert the initial ellipsis, by replacing the last char
			//
			lpStr[nCount-1] = ELLIPSIS;
			GetTextExtentPoint32(hDC, lpStr, nCount, &szStr);

			//
			// While the extents are larger than the width, remove one
			// character at the time
			//
			while(szStr.cx > nWidth && nCount > 1)
			{
				lpStr[--nCount] = 0;			// Remove last
				lpStr[nCount-1] = ELLIPSIS;		// Replace last with ...
	
				GetTextExtentPoint32(hDC, lpStr, nCount, &szStr);
			}
		}

		//
		// Remove the formatting options, just in case
		//
		uFormat &= ~(DT_END_ELLIPSIS | DT_MODIFYSTRING);
	}
	
	return DrawText(hDC, lpString, nCount, lpRect, uFormat);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -