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

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds