Different shift length result of TextOut between Window 7 and Window XP

143 views Asked by At

As title, I use CDC tool to painting text, as follow code, and use the nXOffset variable to shift location to align my text, but result of shift length is deference in windows 7 and windows xp, windows 7 is OK, but window xp does not my expectation. How to solve it, and what kind of problem to make it ?

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

There are 1 answers

0
egur On BEST ANSWER

You can calculate the text rect and shift accordingly:

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