owner darw .The code below shows an example for an owner-drawn ListView control in a form view. BEGIN_MESSAGE_MAP(CMyView, CFormView) ON_WM_MEASUREITEM() ... END_MESSAGE_MAP()// WM_MEASUREITEM is sent to parent of list control void CMyView::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) { if (nIDCtl == IDC_LIST1) { // Calculate appropriate font height. int newHeight = 0; CFont* pFont = (CFont*)GetFont(); if (pFont) { LOGFONT lf; pFont->GetLogFont(&lf); newHeight = (lf.lfHeight > 0) ? lf.lfHeight : -lf.lfHeight; } // Set new itemHeight, use 14 as default height. lpMeasureItemStruct->itemHeight = newHeight ? newHeight : 14; } CFormView::OnMeasureItem(nIDCtl, lpMeasureItemStruct); } IDC_LIST1 is the ID of the owner-drawn ListView control.
m_listctrl.SetExtendedStyle(m_listctrl.GetExtendedStyle()|LVS_EX_FLATSB);可以使用浮动滚动条
BEGIN_MESSAGE_MAP(CMyView, CFormView)
ON_WM_MEASUREITEM()
...
END_MESSAGE_MAP()// WM_MEASUREITEM is sent to parent of list control
void CMyView::OnMeasureItem(int nIDCtl,
LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
if (nIDCtl == IDC_LIST1) { // Calculate appropriate font height.
int newHeight = 0;
CFont* pFont = (CFont*)GetFont();
if (pFont) {
LOGFONT lf;
pFont->GetLogFont(&lf);
newHeight = (lf.lfHeight > 0) ? lf.lfHeight : -lf.lfHeight;
} // Set new itemHeight, use 14 as default height.
lpMeasureItemStruct->itemHeight = newHeight ? newHeight : 14;
}
CFormView::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}
IDC_LIST1 is the ID of the owner-drawn ListView control.