明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

怎么在指定矩形中旋轉(zhuǎn)顯示文字

[摘要]徐景周/////////////////////////////////////////////////////////說(shuō)明:// 在矩形框中旋轉(zhuǎn)方式顯示文字,jingzhou xu//參數(shù): ...
徐景周

///////////////////////////////////////////////////////
//說(shuō)明:
//  在矩形框中旋轉(zhuǎn)方式顯示文字,jingzhou xu
//參數(shù):    
//  pDC:      DC指針
//  str:      顯示文字
//  rect:      顯示范圍
//  angle:      旋轉(zhuǎn)角度
//   nOptions:   ExtTextOut()中相應(yīng)設(shè)置<ETO_CLIPPED 和 ETO_OPAQUE>
///////////////////////////////////////////////////////
void DrawRotatedText(CDC* pDC, const CString str, CRect rect,
                     double angle, UINT nOptions)
{
   //按比例轉(zhuǎn)換角度值
   double pi = 3.141592654;
   double radian = pi * 2 / 360 * angle;

   //獲取顯示文字中心點(diǎn)
   CSize TextSize = pDC->GetTextExtent(str);
   CPoint center;
   center.x = TextSize.cx / 2;
   center.y = TextSize.cy / 2;

   //計(jì)算顯示文字新的中心點(diǎn)
   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知識(shí)庫(kù)”,CRect(100,100,300,300),15, ETO_CLIPPED);