首页 > 代码库 > listctrl调整表头高度

listctrl调整表头高度

CListCtrl派生类下CMyListCtrl.h

class CMyListCtrl :public CListCtrl
{
    public:  
   // 设置表头高度
    void SetHeadHeight(float Height);
}



void CMyListCtrl::SetHeadHeight(float Height)
{
    m_Head.m_fHeight = Height;
}

CHeaderCtrl派生类CMyHeadCtrl插入HDM_LAYOUT消息

class CMyHeadCtrl :public CHeaderCtrl
{
    LRESULT OnLayout(WPARAM wParam, LPARAM lParam);
}

BEGIN_MESSAGE_MAP(CMyHeadCtrl, CHeaderCtrl)
     ON_MESSAGE(HDM_LAYOUT, OnLayout)
END_MESSAGE_MAP()

CMyHeadCtrl::CMyHeadCtrl() : 
{

    m_fHeight = 1.5;    //默认列头高度是一倍数
}

LRESULT CMyHeadCtrl::OnLayout(WPARAM wParam, LPARAM lParam)
{
    LRESULT lResult = CHeaderCtrl::DefWindowProc(HDM_LAYOUT, 0, lParam);
    HD_LAYOUT &hdl = *(HD_LAYOUT *)lParam;
    RECT *prc = hdl.prc;
    WINDOWPOS *pwpos = hdl.pwpos;

    //表头高度为原来1.5倍,如果要动态修改表头高度的话,将1.5设成一个全局变量 
    int nHeight = (int)(pwpos->cy * m_fHeight);
    pwpos->cy = nHeight;
    prc->top = nHeight;

    return lResult;
}

 

listctrl调整表头高度