pOldFont = pDC->SelectObject( &NewFont );
GetTextMetrics( pDC->m_hDC, &tm );
rect.left = nStart + tm.tmAveCharWidth * strlen( "P6V" );
rect.top = m_rect.bottom + nToBottom + 2;
rect.right = rect.left + nWidth;
rect.bottom = rect.top + nHight - 2;
pDC->SetTextColor( P6VCOLOR );
pDC->TextOut( nStart, m_rect.bottom + nToBottom, "P6V" );
pDC->FillRect( rect, &CBrush( P6VCOLOR ) );上面是主要代码,我想要的效果是输出“P6V[]”后面的"[]"在实际绘图时是一个矩形,只是不好表示,我就用“[]”代替了。
但实际的输出效果是"P6[]",也就是在输出矩形时偏前了一点,把"V"给覆盖掉了。请问这是为什么?
tm.tmAveCharWidth = 6;
rect.left = 68
没看出什么问题。
改成:
rect.left = nStart + tm.tmAveCharWidth * strlen( "P6V" )*2;