// 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,
CRect(10,10,200,200), 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;
}
}
为了使MeasureItem能够被调用,必须设置CBS_OWNERDRAWVARIABLE属性,但设置了该属性之后,编译通过之后,一运行就出错,去掉以后虽然没错但改变不了高度,请问高手这是哪儿的问题?
// 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,
CRect(10,10,200,200), 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;
}
}
为了使MeasureItem能够被调用,必须设置CBS_OWNERDRAWVARIABLE属性,但设置了该属性之后,编译通过之后,一运行就出错,去掉以后虽然没错但改变不了高度,请问高手这是哪儿的问题?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货