dcsimg

MeasureItem for dynamic font changing in a list control

WEBINAR:
On-Demand

Application Security Testing: An Integral Part of DevOps


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
  • You must have javascript enabled in order to post comments.

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

Top White Papers and Webcasts

  • A CRM solution holds a wealth of information and document generation tools allow users to take that information and create documents with both visual appeal and function. Document generation is the process of automatically producing a file and document generation applications save companies time, mistakes, and money. You bought Salesforce to be more efficient — why are you still manually creating proposals, contracts, invoices, and account plans? Read this eBook to learn how you can automate virtually …

  • CEOs, CIOs, boards and shareholders are demanding digital transformation. They want their organizations to be more customer-focused, competitive and strategic to increase revenue. Data drives all of those aspects. A great first step in optimizing data use is moving data to the cloud. It can quickly show benefits. Here are six aspects of a cloud data management strategy that will help your organization more fully move, manage and use valuable data to successfully support digital transformation.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.