If you want to fit the text into some width, then maybe try several font sizes. For example, the next loop starts with 6-point font and increases it until the width is achieved:
CString text = L"Marks sample";
CString font_name = L"Arial";
int required_width_points = 81;
float font_size_points;
CClientDC dc( this );
dc.SetMapMode( MM_TWIPS );
int required_width_twips = required_width_points * 20;
for( font_size_points = 6.0;; font_size_points += 0.1 )
{
CFont font;
font.CreatePointFont( font_size_points * 10, font_name, &dc );
CFont* old_font = dc.SelectObject( &font );
CRect r( 0, 0, 0, 0 );
dc.DrawText( text, r, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_NOCLIP | DT_NOPREFIX | DT_CALCRECT );
dc.SelectObject( old_font );
if( r.Width( ) == required_width_twips ) break;
if( r.Width( ) > required_width_twips )
{
font_size_points -= 0.1;
break;
}
}
This is the current window (a CWnd*). The result is in font_size_points.
You can also consider a binary search algorithm.