使所有列拥有共同的最小和最大列宽
声明常量
class CMyCtrl/CMyView :
public CListCtrl/CListView
{
...
protected:
const int m_nMinWidth = 80;
const int m_nMaxWidth = 320;
...
}
重载虚函数OnNotify
BOOL CMyCtrl/CMyView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
HD_NOTIFY* pHDN = (HD_NOTIFY*)lParam;
switch (pHDN->hdr.code)
{
case HDN_ITEMCHANGINGA:
case HDN_ITEMCHANGINGW:
if (pHDN->pitem->cxy < m_nMinWidth) // 最小列宽
pHDN->pitem->cxy = m_nMinWidth;
else if (pHDN->pitem->cxy > m_nMaxWidth) // 最大列宽
pHDN->pitem->cxy = m_nMaxWidth;
break;
default:
break;
}
return CListView::OnNotify(wParam, lParam, pResult);
}
使每一列单独拥有最小和最大列宽
声明常量数组
class CMyCtrl/CMyView :
public CListCtrl/CListView
{
...
protected:
const int m_nMinWidth[4] = { 80,80,100,100 };
const int m_nMaxWidth[4] = { 320,320,300,300 };
...
}
重载虚函数OnNotify
BOOL CMyCtrl/CMyView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
HD_NOTIFY* pHDN = (HD_NOTIFY*)lParam;
switch (pHDN->hdr.code)
{
case HDN_ITEMCHANGINGA:
case HDN_ITEMCHANGINGW:
if (pHDN->pitem->cxy < m_nMinWidth[pHDN->iItem]) // 最小列宽
pHDN->pitem->cxy = m_nMinWidth;
else if (pHDN->pitem->cxy > m_nMaxWidth[pHDN->iItem]) // 最大列宽
pHDN->pitem->cxy = m_nMaxWidth;
break;
default:
break;
}
return CListView::OnNotify(wParam, lParam, pResult);
}