MeasureItem for dynamic font changing in a list control

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

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

  • Read the ebook Hybrid Cloud & Data Fabric for Dummies to learn how a Data Fabric can ease data management complexity within a hybrid cloud and help you maximize the control of your data — from anywhere at any time. Find out how to: Seamlessly and dynamically move data across private and public cloud resources Keep data secure and minimize business disruptions …

  • When moving workloads to Amazon Web Services (AWS), a comprehensive data protection strategy is key. Check out these 5 important data protection steps designed to make your move to AWS successful.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date