Partager via


CComboBox::MeasureItem

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

virtual void MeasureItem( 
   LPMEASUREITEMSTRUCT lpMeasureItemStruct  
);

Parameters

Remarks

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

Using the CBS_OWNERDRAWFIXED style in an owner-draw combo box created with the SubclassDlgItem member function of CWnd involves further programming considerations. See the discussion in Technical Note 14.

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

Example

// CMyComboBox is my owner-drawn combo box derived from CComboBox. This  
// example measures an item and sets the height of the item to twice the  
// vertical extent of its text. The combo box control was created with  
// the following code: 
//   pmyComboBox->Create( 
//      WS_CHILD|WS_VISIBLE|WS_BORDER|WS_HSCROLL|WS_VSCROLL| 
//      CBS_SORT|CBS_OWNERDRAWVARIABLE, 
//      myRect, pParentWnd, 1); 
// 
void CMyComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
   ASSERT(lpMeasureItemStruct->CtlType == ODT_COMBOBOX);

   if (lpMeasureItemStruct->itemID != (UINT) -1)
   {
      LPCTSTR lpszText = (LPCTSTR) lpMeasureItemStruct->itemData;
      ASSERT(lpszText != NULL);
      CSize   sz;
      CDC*    pDC = GetDC();

      sz = pDC->GetTextExtent(lpszText);

      ReleaseDC(pDC);

      lpMeasureItemStruct->itemHeight = 2*sz.cy;
   }
}

Requirements

Header: afxwin.h

See Also

Reference

CComboBox Class

Hierarchy Chart

CComboBox::CompareItem

CComboBox::DrawItem

WM_MEASUREITEM

CComboBox::DeleteItem