DrawText() with DT_EXPANDTABS: how to set the "reference point" of
tab stops?
I'd like to draw 3 chars (W, tab, M) as below:
W\tM
If I call DrawText() to draw all 3 chars at a time, I have:
W M
However, if I draw "W" first, then "\tM", the output is slightly
different (more space in between):
W M
When drawing "\tM", I have to first update the target rect's left
bound. This apparently changed the "reference point" for drawing tabs.
Is it possible to draw in two steps without changing the "reference
point" of tab stops? Any idea is appreciated.
---------------------------
My code that demos above-mentioned output:
void _DrawText(CDCHandle dc)
{
UINT uFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE |
DT_EXPANDTABS;
CRect rect(0, 0, 200, 20);
// First line: draw all chars at a time
{
dc.DrawText(_T("W\tM"), -1, rect, uFormat);
}
// Second line: draw "W" first
{
rect.OffsetRect(0, 30); // go to next line
dc.DrawText(_T("W"), -1, rect, uFormat);
}
// Update rect's left bound:
{
CRect rcText;
dc.DrawText(_T("W"), -1, rcText, uFormat | DT_CALCRECT);
rect.left += rcText.Width();
}
// Second line: draw "\tM" in the updated rect
{
dc.DrawText(_T("\tM"), -1, rect, uFormat);
}
}