zoukankan      html  css  js  c++  java
  • C++ Code_ScrollBar

    主题

    1.  ScrollBar的使用

    2.  

    3.  

    4.  

    5.  

        

      属性

    HScrollBar

    VScrollBar

    直接拖拽1其中任意空间到对话框上面是,你一拖拽滚动条,它立即回到原始位置

        
        

    代码::

      

    /*

    在控件上面添加1个HScrollBar和1个Edit控件

     

    */

    //初始化部分添加代码

        // TODO: Add extra initialization here
        CScrollBar *pScroll=(CScrollBar*)GetDlgItem(IDC_SCROLLBAR1);
        pScroll->SetScrollRange(0, 100);
        pScroll->SetScrollPos(0);

        SetDlgItemInt(IDC_EDIT1, 0);

     

    //为对话杠添加1个OnHScroll消息,添加如下代码

    void CProject01Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
    {
        // TODO: Add your message handler code here and/or call default
        int iPos=pScrollBar->GetScrollPos();
        switch (nSBCode)
        {
        case SB_LINERIGHT:
                iPos+=1;
                break;
        case SB_LINELEFT:
                iPos-=1;
                break;
        case SB_PAGERIGHT:
                iPos+=10;
                break;
        case SB_PAGELEFT:
                iPos-=10;
                break;
        case SB_THUMBTRACK:
                iPos=nPos;
                break;
        default:
            break;
        }
        if (iPos<0) iPos=0;
        if (iPos>100) iPos=100;
        pScrollBar->SetScrollPos(iPos);
        SetDlgItemInt(IDC_EDIT1, iPos);
        
        CDialog::OnHScroll(nSBCode, nPos, pScrollBar);

    }

     

    //为Edit1添加OnChange消息

    void CProject01Dlg::OnChangeEdit1()
    {
        // TODO: If this is a RICHEDIT control, the control will not
        // send this notification unless you override the CDialog::OnInitDialog()
        // function and call CRichEditCtrl().SetEventMask()
        // with the ENM_CHANGE flag ORed into the mask.
        CString STR;
        GetDlgItemText(IDC_EDIT1, STR);
        STR.TrimLeft();
        STR.TrimRight();
        INT iPos=0;
        if (STR!="-" && STR!="")
        {
            if (!UpdateData())
            {
                return;
            }
            iPos=m_nEdt1;
        }
        CScrollBar *pScroll=(CScrollBar*)GetDlgItem(IDC_SCROLLBAR1);
        pScroll->SetScrollPos(iPos);
        
        // TODO: Add your control notification handler code here
        
    }
     
        

    效果图:

      





    附件列表

    • 相关阅读:
      胜利大逃亡
      求最小环
      Prime算法
      网站根目录下没有正确的DNT.config文件 (不同类型错误更新中)
      Day4_代码重用与函数
      Day1_算法分析方法
      Day3_字符串操作与正则表达式
      错误解决一_call time passbyreference removed
      Day1_PHP快速入门
      silverlight 动态加载树形菜单[带图标],方法一
    • 原文地址:https://www.cnblogs.com/xe2011/p/3885723.html
    Copyright © 2011-2022 走看看