如何在指定矩形中旋转显示文字
敬业的IT人
互联网
佚名
2008-1-4 18:48:58
徐景周
///////////////////////////////////////////////////////
//说明:
// 在矩形框中旋转方式显示文字,jingzhou xu
//参数:
// pDC: DC指针
// str: 显示文字
// rect: 显示范围
// angle: 旋转角度
// nOptions: ExtTextOut()中相应设置<ETO_CLIPPED 和 ETO_OPAQUE>
///////////////////////////////////////////////////////
void DrawRotatedText(CDC* pDC, const CString str, CRect rect,
double angle, UINT nOptions)
{
//按比例转换角度值
double pi = 3.141592654;
double radian = pi * 2 / 360 * angle;
//获取显示文字中心点
CSize TextSize = pDC->GetTextExtent(str);
CPoint center;
center.x = TextSize.cx / 2;
center.y = TextSize.cy / 2;
//计算显示文字新的中心点
CPoint rcenter;
rcenter.x = long(cos(radian) * center.x - sin(radian) * center.y);
rcenter.y = long(sin(radian) * center.x cos(radian) * center.y);
//绘制文字
pDC->SetTextAlign(TA_BASELINE);
pDC->SetBkMode(TRANSPARENT);
pDC->ExtTextOut(rect.left rect.Width() / 2 - rcenter.x,
rect.top rect.Height() / 2 rcenter.y,
nOptions, rect, str, NULL);
}
用法:
DrawRotatedText (pDC,”VC知识库”,CRect(100,100,300,300),15, ETO_CLIPPED);
///////////////////////////////////////////////////////
//说明:
// 在矩形框中旋转方式显示文字,jingzhou xu
//参数:
// pDC: DC指针
// str: 显示文字
// rect: 显示范围
// angle: 旋转角度
// nOptions: ExtTextOut()中相应设置<ETO_CLIPPED 和 ETO_OPAQUE>
///////////////////////////////////////////////////////
void DrawRotatedText(CDC* pDC, const CString str, CRect rect,
double angle, UINT nOptions)
{
//按比例转换角度值
double pi = 3.141592654;
double radian = pi * 2 / 360 * angle;
//获取显示文字中心点
CSize TextSize = pDC->GetTextExtent(str);
CPoint center;
center.x = TextSize.cx / 2;
center.y = TextSize.cy / 2;
//计算显示文字新的中心点
CPoint rcenter;
rcenter.x = long(cos(radian) * center.x - sin(radian) * center.y);
rcenter.y = long(sin(radian) * center.x cos(radian) * center.y);
//绘制文字
pDC->SetTextAlign(TA_BASELINE);
pDC->SetBkMode(TRANSPARENT);
pDC->ExtTextOut(rect.left rect.Width() / 2 - rcenter.x,
rect.top rect.Height() / 2 rcenter.y,
nOptions, rect, str, NULL);
}
用法:
DrawRotatedText (pDC,”VC知识库”,CRect(100,100,300,300),15, ETO_CLIPPED);
- 最新文章
- 如何判断当前操作系统的版本[01-04]
- VC下实现DirectSound[01-04]
- 在VC应用程序中插入微型动画[01-04]
- Visual C 应用框架揭密[01-04]
- 利用VC 编写Windows95的CPL组件[01-04]
- 如何在VC 程序中获得其他程序的图标[01-04]
- 相关文章
