在进度条上分了很多个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);
}