主题

1.
滑块控件属性设置

2.
使用滑块控件设置颜色

3.
显示Slider的数值

4.

5.

    

属性

滑块控件属性设置

//代码设置属性

    

代码::

/////////////////////////////////////////////////////////////////////////////
// CProject02Dlg dialog
//class CProject02Dlg : public CDialog
//{
// Construction
//public:
//    CProject02Dlg(CWnd* pParent = NULL);    // standard constructor
    COLORREF m_clColor;

// Dialog Data

在CProject02Dlg中右键添加个Add MemberFunction

void CProject02Dlg::updatePicCtrl()
{
    CDC * pDC = m_ctrl_pic1.GetDC();
    CRect rc;
    m_ctrl_pic1.GetClientRect(rc);
    pDC -> FillRect(rc, & CBrush(m_clColor));
    m_ctrl_pic1.ReleaseDC(pDC);

}

 
在BOOL
CProject02Dlg::OnInitDialog()
部分添加slider的初始化部分代码
    // TODO: Add extra initialization
here
    m_ctrl_Slider1_Red.SetRange(0,255,FALSE);
    m_ctrl_Slider2_Green.SetRange(0,255,FALSE);

m_ctrl_Slider3_Blue.SetRange(0,255,FALSE);

 
 
void CProject02Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollBar)
{

    // TODO: Add your message handler code here and/or
call default
    if (nSBCode == SB_THUMBTRACK)
    {
        if
(pScrollBar -> m_hWnd == m_ctrl_Slider1_Red.m_hWnd)
        {
            m_nEdt1_Red = nPos;
            UpdateData(FALSE);
        }
        
        if
(pScrollBar -> m_hWnd == m_ctrl_Slider2_Green.m_hWnd)
        {
            m_nEdt2_Green = nPos;
            UpdateData(FALSE);
        }
        
        if
(pScrollBar -> m_hWnd == m_ctrl_Slider3_Blue.m_hWnd)
        {
            m_nEdt3_Blue = nPos;
            UpdateData(FALSE);
        }
        
        m_clColor = RGB(m_nEdt1_Red,m_nEdt2_Green,m_nEdt3_Blue);
        updatePicCtrl();
    }

CDialog::OnHScroll(nSBCode, nPos, pScrollBar); }

 
//为每个Edit添加个EN_Change消息
void CProject02Dlg::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.
    
    // TODO: Add your control notification handler code
here
    UpdateData(TRUE);
    m_ctrl_Slider1_Red.SetPos(m_nEdt1_Red);
    updatePicCtrl();    
}
void CProject02Dlg::OnChangeEdit2()
{
    // 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.
    
    // TODO: Add your control notification handler code
here
    UpdateData(TRUE);
    m_ctrl_Slider2_Green.SetPos(m_nEdt2_Green);
    updatePicCtrl();    
}
 
void CProject02Dlg::OnChangeEdit3()
{
    // 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.
    
    // TODO: Add your control notification handler code
here
    UpdateData(TRUE);
    m_ctrl_Slider3_Blue.SetPos(m_nEdt3_Blue);
    updatePicCtrl();
    

}

    

效果图:

 
 
 

附件列表

C++ Code_Slider的更多相关文章

随机推荐

  1. 三年程序学习之二:(对web初认识)

    接着上一篇讲,之后第二天我就来公司上班了,主要是前端,CSS+DIV,table,网站维护之类的,这样的日子过了将近3个星期,一直没什么进展,自己也学不到什么技术,不过我觉得CSS+DIV我算是基础的 ...

  2. VS常用技巧

    VS2005代码编辑器的展开和折叠代码确实很方便和实用.以下是展开代码和折叠代码所用到的快捷键,很常用: Ctrl + M + O: 折叠所有方法 Ctrl + M + M: 折叠或者展开当前方法 C ...

  3. iOS优秀博客收录(持续更新)

    唐巧 王巍 破船之家 NSHipster Limboy 无网不剩 念茜的博客 Xcode Dev Ted’s Homepage txx’s blog KEVIN BLOG 阿毛的蛋疼地 亚庆的 Blo ...

  4. javascript 作用域例子

    for(var i=0,l=url1.length;i<l;i++){ var url = url1[i]; setTimeout(function(){ window.open(url); } ...

  5. 前端异步解决方案——mmDeferred

    Deferred是前端解决异步操作的一种编程范式,后来出现的Promise规范更是让其普适性大大提高.不过Promise规范也存在分岐.现在最流行的是Promise/A规范. Promise/A大致是 ...

  6. ARM内核全解析

    前不久ARM正式宣布推出新款ARMv8架构的Cortex-A50处理器系列产品,以此来扩大ARM在高性能与低功耗 领域的领先地位,进一步抢占移动终端市场份额.Cortex-A50是继Cortex-A1 ...

  7. ACM之数学题

    数学题,始终记得,第一次被带飞师大校赛以及省赛,毫无例外的在数学题上卡死....因此,现在开始,有意识的保留遇见的数学题...(下列知识点按遇见先后顺序排列: 1欧拉公式 欧拉公式的用处是,找出小于N ...

  8. ImageSwitcher的应用

    在android的开发中很多时候都会用到图片的切换,我相信大家在安装完apk后,都会遇到弹出用户向导,介绍本版本apk的新功能,如果你用的是平板电脑或手机的话,可以左右滑动以切换视图,如果你用的是an ...

  9. LeetCode 刷题记录

    写在前面:因为要准备面试,开始了在[LeetCode]上刷题的历程.LeetCode上一共有大约150道题目,本文记录我在<http://oj.leetcode.com>上AC的所有题目, ...

  10. C# 与 C++ 数据类型对照

    C++            C#=====================================WORD            ushortDWORD            uintUCH ...