您的位置:首页 > 其它

如何将无法显示的字符串用。代替

2008-09-08 09:12 232 查看
在进度条上分了很多个RECT,每个RECT都 显示一个Operation名字,当 名字很长时,无法显示全部,这时候需要对字符串做处理。我的方法是,当字符串的长度小于RECT的宽度时,直接将字符串在RECT的中间显示。当大于RECT的宽度时,则需要以RECT的宽度为基准。具体实现C++代码如下:

CSize size = dc.GetTextExtent(str);
if(size.cx<=m_pArrRects[i].Height()) //when rect.Weigth<=currently rect.height,direct showing;
{
dc.TextOut(m_pArrRects[i].CenterPoint().x + size.cy/2 ,m_pArrRects[i].CenterPoint().y-size.cx/2,str);
}
else//when rect.Weigth>currently rect.height,delete the end character to adapt the rect
{
int strLength=(m_pArrRects[i].Height()-40)/10;
if(strLength%2==1)//Use for Jap,and chinese
{
strLength=strLength+1;
}
CString strAdd="...";
CString strShort;
strShort=str.Left(strLength);
strShort+=strAdd;
dc.TextOut(m_pArrRects[i].CenterPoint().x + size.cy/2 ,m_pArrRects[i].top,strShort);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐