質問

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());
役に立ちましたか?

解決

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();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top