1

作为标题,我使用CDC工具绘制文本,如下代码,并使用nXOffset变量移动位置以对齐我的文本,但移位长度的结果在windows 7和windows xp中是尊重的,windows 7是可以的,但是window xp不是我的期望。如何解决它,以及制造什么样的问题?

CDC*       m_cdcRealTimeValue;
m_cdcRealTimeValue->SelectObject(&mFont);
m_cdcRealTimeValue->SetTextColor(colorText);
m_cdcRealTimeValue->TextOut(rectRealTime.Width() - nXOffset,
        (int)(nRealTimeRg[1] + nYGapRealTime[0]), strTempPVLastMove.Left(nPreDot), strTempPVLastMove.Left(nPreDot).GetLength());
4

1 回答 1

0

您可以计算文本 rect 并相应地移位:

 CRect r(0, 0, 0, 0); // will hold the text rect
 m_cdcRealTimeValue->DrawText(text, textLen, r, DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_CALCRECT);
 int textWidth = r.Width();
于 2013-12-17T14:19:21.697 回答