Exemple #1
0
//如果内容太长显示不完则用省略号表示
void  ShowAsShort(TCtrl *pTCtrl, TUChar* pCaptionString, TFont objFontType)
{
	TRectangle Rc_TCtrl;
	pTCtrl->GetBounds(&Rc_TCtrl);
	
	int nStrLen = TUString::StrLen(TUString::StrTrimUnVisible(pCaptionString));
	//int nShortWidth = GetShowAllStringWidth((TUChar*)L"...",objFontType);
	int nShortWidth = GetShowAllStringWidth((TUChar*)TUSTR_Kx_Ellipsis,objFontType);	
	int nShowLen = objFontType.WordWrapNoLF(TUString::StrTrimUnVisible(pCaptionString), Rc_TCtrl.Width()- nShortWidth*2);

	if (nShowLen < nStrLen)
	{
		//Add one more label to show
		
		TUChar* pszTemp = new TUChar[nShowLen + 10];
		MemSet( (void *)pszTemp, 0x0, sizeof(TUChar) * (nShowLen + 10) );
		TUString::StrNCopy(pszTemp,TUString::StrTrimUnVisible(pCaptionString),nShowLen);
		TUString::StrCat(pszTemp,TUSTR_Kx_Ellipsis);//(const TUChar*)L"..."
		pTCtrl->SetCaption(pszTemp,FALSE);
		delete pszTemp;	
	}
	else
	{
		pTCtrl->SetCaption(TUString::StrTrimUnVisible(pCaptionString),FALSE);//StrTrim
	}	
}
Exemple #2
0
//根据字体计算出显示整个字串所需的像素
//Todo::WordWrapNoLF有问题, 如果第一个字节为空格,返回的nShowLen长度有问题,需要做去头空格处理
Int32 GetShowAllStringWidth(TUChar* pCaptionString, TFont objFontType)
{
	Int32 Width = 1;
	Int32 tempWidth = 0;//从像素0开始
	Int32 nStringLen = TUString::StrLen(pCaptionString);
	Int32 nShowLen = 0;
	do
	{
		tempWidth ++;
		nShowLen = objFontType.WordWrapNoLF(TUString::StrTrimUnVisible(pCaptionString), tempWidth);
		
	}while(nShowLen < nStringLen);

	return tempWidth + 4;//刚刚好的长度显示字串时有问题,故再加两个像素
}