MeasureItem for dynamic font changing in a list control
Posted
by Peter Ierardi
on October 11th, 1998
The code snip below responds correctly to font changes by selecting the font object into the Client Dc, then obtains the text metrics. Note that we are adding tmHeight and tmExternalLeading values to cover the glyphs that extend beyond the normal height boundaries of a given font.
void CMyListCtrl::MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct )
{
CClientDC dc( this );
CFont* pFont = GetFont();
ASSERT( pFont );
CFont* pOldFont = dc.SelectObject( pFont );
ASSERT( pOldFont );
TEXTMETRIC txtMetric;
BOOL bRet = dc.GetTextMetrics( &txtMetric );
ASSERT( bRet );
int cyChar = txtMetric.tmHeight + txtMetric.tmExternalLeading;
ASSERT( 0 != cyChar );
lpMeasureItemStruct->itemHeight = cyChar;
}
Last updated: 29 July 1998 by Rob Osborne

Comments
You must say something about reflected messages.
Posted by Legacy on 11/05/1998 12:00amOriginally posted by: Mihai
Reply