• 对话框子窗口的滚动


    父类
    void CDlgXXXX::InitUIRes(CString strCatCode)
    {
    	if (NULL == m_pDlgSub_)
    	{
    		m_pDlgSub_ = new CDlgFilterSub(this);
    		m_pDlgSub_->Create(CDlgFilterSub::IDD, this);
    	}
    	
    	m_pDlgSub_->InitUI(strCatCode);
    
    	CRect rtClient;
    	GetWindowRect(&rtClient);
    
    	CRect rtDlg;
    	m_pDlgSub_->GetClientRect(&rtDlg);
    	rtDlg.MoveToY(40);
    	rtDlg.left = 0;
    	rtDlg.right = rtClient.Width();
    	m_pDlgSub_->MoveWindow(rtDlg);
    
    	m_pDlgSub_->GetWindowRect(&rtDlg);
    	rtClient.bottom = rtDlg.bottom + 10;
    	MoveWindow(rtClient);
    
    	if (!m_pDlgSub_->IsWindowVisible())
    	{
    		m_pDlgSub_->ShowWindow(SW_SHOW);
    	}
    }
    

      子窗口

    void CDlgFilterSub::InitUI(CString strCatCode)
    {
    	。。。。动态添加按钮

    CRect rtClient;
    GetClientRect(rtClient);

    rtCtrl最后一排控件的位置

    SCROLLINFO si;
    si.cbSize = sizeof(si);
    GetScrollInfo(SB_VERT, &si);
    si.nMax = max(rtCtrl.bottom + SPACE, rtClient.bottom);
    si.nPos = 0;
    SetScrollInfo(SB_VERT, &si);

    static int iHeight = rtClient.bottom;
    if (rtClient.bottom < rtCtrl.bottom + SPACE)
    {
    rtClient.bottom = iHeight;
    }
    else
    {
    rtClient.bottom = rtCtrl.bottom + SPACE;
    }
    MoveWindow(rtClient);

    }
    

      子窗口的初始化

    BOOL CDlgFilterSub::OnInitDialog()
    {
    	CBCGPDialog::OnInitDialog();
    	COLORREF bgColor = RGB(248, 248, 248);
    	SetBackgroundColor(bgColor);
    
    	CRect rtClient;
    	GetClientRect(rtClient);
    	SCROLLINFO si;
    	si.cbSize = sizeof(SCROLLINFO);
    	si.fMask = SIF_ALL;
    	si.nPos = 0;
    	si.nMin = 0;
    	si.nMax = rtClient.bottom;
    	SetScrollInfo(SB_VERT, &si);
    
    	return TRUE;
    }
    

      

    void CDlgFilterSub::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
    {
    	SCROLLINFO si;
    	si.cbSize = sizeof(si);
    	si.fMask = SIF_ALL;
    	GetScrollInfo(SB_VERT, &si);
    	INT nVscroll = si.nPos;
    	switch(nSBCode)
    	{  
    	case SB_LINEDOWN:
    		{
    			nVscroll += 20;
    			if (nVscroll > (si.nMax - si.nMin - si.nPage ))
    			{
    				nVscroll = si.nMax - si.nMin - si.nPage;
    			}
    		}
    		break;
    	case SB_LINEUP:
    		{
    			nVscroll -= 20;
    			if (nVscroll < si.nMin)
    			{
    				nVscroll = 0;
    			}
    		}
    		break;
    	case SB_PAGEDOWN:
    		{
    			nVscroll += si.nPage;
    			if (nVscroll > (si.nMax - si.nMin - si.nPage))
    			{
    				nVscroll = si.nMax - si.nMin - si.nPage;
    			}
    		}
    		break;
    	case SB_PAGEUP:
    		{
    			nVscroll -= si.nPage;
    			if (nVscroll < si.nMin)
    			{
    				nVscroll = 0;  
    			}
    		}
    		break;
    	case SB_THUMBTRACK:
    		{
    			nVscroll = nPos;
    		}
    		break;
    	}
    
    	if (si.nPos != nVscroll)
    	{
    		int yAmount = -(nVscroll - si.nPos);
    		ScrollWindow(0, yAmount, NULL,NULL);
    	}
    
    	si.nPos = nVscroll;
    	SetScrollInfo(SB_VERT, &si);
    
    	CBCGPDialog::OnVScroll(nSBCode, nPos, pScrollBar);
    }
    

      

    ON_WM_VSCROLL()
    

      

    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    

      

  • 相关阅读:
    一次偶然的Java内存溢出引发的思考
    centos6.4下面安装postgresql以及客户端远程连接
    用springMVC构建restful程序,接收以及返回json数据格式
    如何编译spring源码,并导入到eclipse中
    模仿MFC封装Windows API
    一些好用的控制台命令
    014:字符串:各种其奇葩的内置方法
    013:元组:戴上了枷锁的列表
    012:列表:一个打了激素的数组3
    011:列表:一个打了激素的数组2
  • 原文地址:https://www.cnblogs.com/XiHua/p/13914988.html
Copyright © 2020-2023  润新知