CComboBox::MeasureItem

调用由结构,当具有所有者描述样式的组合框创建。

virtual void MeasureItem(
   LPMEASUREITEMSTRUCT lpMeasureItemStruct 
);

参数

备注

默认情况下,此成员函数不执行任何操作。重写该成员函数并填充 MEASUREITEMSTRUCT 结构通知Windows列表框的尺寸在组合框上。如果组合框。CBS_OWNERDRAWVARIABLE 样式创建,框架对每个项调用该成员函数的列表框。否则,此成员仅调用一次。

使用请在 CWndSubclassDlgItem 成员函数创建的所有者描述组合框的 CBS_OWNERDRAWFIXED 样式涉及进一步编程注意事项。在参见 技术说明14的讨论。

MEASUREITEMSTRUCT 结构的声明参见 CWnd::OnMeasureItem

示例

// 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;
   }
}

要求

Header: afxwin.h

请参见

参考

CComboBox选件类

层次结构图

CComboBox::CompareItem

CComboBox::DrawItem

WM_MEASUREITEM

CComboBox::DeleteItem