zoukankan      html  css  js  c++  java
  • 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);
    }
    
  • 相关阅读:
    【青橙商城-管理后台开发】2. 商品服务模块搭建
    【青橙商城-管理后台开发】1.公共模块搭建
    Oracle对象-视图和索引
    Oracle的查询-分页查询
    Oracle的查询-子查询
    Oracle的查询-自连接概念和联系
    Oracle的查询-多表查询中的一些概念
    Oracle的查询-分组查询
    Oracle的查询-多行查询
    dotnet 开源库
  • 原文地址:https://www.cnblogs.com/fenggwsx/p/13522152.html
Copyright © 2011-2022 走看看