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);
    }
    
  • 相关阅读:
    我渴望自由和成功(愿与君共勉)
    gdb使用 和core dump文件调试
    谷歌浏览器快捷键大全
    Android适屏
    BestCoder Round #33
    NAT&amp;Port Forwarding&amp;Port Triggering
    程序员应该学习的书
    java代码调用rtx发送提醒消息
    js实现excel导出
    一个跨界程序员:不务正业的这几年,我如何让自己的收入翻了十倍(转)
  • 原文地址:https://www.cnblogs.com/fenggwsx/p/13522152.html
Copyright © 2011-2022 走看看