Windows 窗口7和窗口XP之间TextOut的不同移位长度结果

Windows 窗口7和窗口XP之间TextOut的不同移位长度结果,windows,mfc,textout,Windows,Mfc,Textout,作为标题,我使用CDC工具绘制文本,如下代码所示,并使用nXOffset变量移位位置来对齐文本,但移位长度的结果在windows 7和windows xp中是不同的,windows 7是可以的,但windows xp不是我期望的。 如何解决它,以及制造什么样的问题 CDC* m_cdcRealTimeValue; m_cdcRealTimeValue->SelectObject(&mFont); m_cdcRealTimeValue->SetTextColor(c

作为标题,我使用CDC工具绘制文本,如下代码所示,并使用nXOffset变量移位位置来对齐文本,但移位长度的结果在windows 7和windows xp中是不同的,windows 7是可以的,但windows 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());

您可以相应地计算文本rect和shift:

 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();