MeasureItem for dynamic font changing in a list control

Zafir's article on adjusting row height in a CListCtrl derived class needs to be adjusted when dealing with dynamic font changes. His sample causes some problems where the row height is not correctly computed to compensate for different video display modes.

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:00am

    Originally posted by: Mihai

    Sincerely, Mihai Filimon
    

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

  • As everyone scrambles to protect customers and consumers from the Heartbleed virus, there will be a variety of mitigating solutions offered up to address this pesky bug. There are a variety of points within the data path where solutions could be put into place to mitigate this (and similar) vulnerabilities and customers must choose the most strategic point in the network at which to deploy their selected mitigation. Read this white paper to learn the ins and outs of mitigating the risk of Heartbleed and the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds