• MFC中设置列表控件(或列表视图)的最小和最大列宽


    使所有列拥有共同的最小和最大列宽

    声明常量

    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);
    }
    
  • 相关阅读:
    2014最后一篇英语笔记(新开始)
    记录:CSS特殊性——权值规则
    grunt--自动化打包工具使用
    【移动端】---点透事件
    [前端性能提升]--图片转化为base64
    js--cookie
    1.倒数几秒弹窗关闭
    ES6就是ES2015 的主要内容
    call 与 apply的区别
    34枚金币时间管理法
  • 原文地址:https://www.cnblogs.com/fenggwsx/p/13522152.html
Copyright © 2020-2023  润新知