Export (0) Print
Expand All


Called by the framework when a list box with an owner-draw style is created.

virtual void MeasureItem( 
   LPMEASUREITEMSTRUCT lpMeasureItemStruct  


A long pointer to a MEASUREITEMSTRUCT structure.

By default, this member function does nothing. Override this member function and fill in the MEASUREITEMSTRUCT structure to inform Windows of the list-box dimensions. If the list box is created with the LBS_OWNERDRAWVARIABLE style, the framework calls this member function for each item in the list box. Otherwise, this member is called only once.

For further information about using the LBS_OWNERDRAWFIXED style in an owner-draw list box created with the SubclassDlgItem member function of CWnd, see the discussion in Technical Note 14.

See CWnd::OnMeasureItem for a description of the MEASUREITEMSTRUCT structure.

// CMyODListBox is my owner-drawn list box derived from CListBox. This  
// example measures an item and sets the height of the item to twice the  
// vertical extent of its text. The list box control was created with the  
// following code: 
//   m_myODListBox.Create( 
//      CRect(10,250,200,450), pParentWnd, IDC_MYODLISTBOX); 
void CMyODListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
   ASSERT(lpMeasureItemStruct->CtlType == ODT_LISTBOX);
   LPCTSTR lpszText = (LPCTSTR) lpMeasureItemStruct->itemData;
   ASSERT(lpszText != NULL);
   CSize   sz;
   CDC*    pDC = GetDC();

   sz = pDC->GetTextExtent(lpszText);


   lpMeasureItemStruct->itemHeight = 2*sz.cy;

Header: afxwin.h

Community Additions

© 2015 Microsoft