CSliderCtrl本身的一些消息没有这个好用,一般可以通过在对话框上直接添加OnHScroll,通过参数判断CSliderCtrl,然后判断响应相关消息;
函数原型:afx_msg void OnHScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar );
- SB_LEFT Scroll to far left. // 按Home键时触发
- SB_ENDSCROLL End scroll.//结束对滚动条的控制时触发,比如点击滚动条,当鼠标左键弹起时便叫结束控制
- SB_LINELEFT Scroll left.//按方向键时触发
- SB_LINERIGHT Scroll right.//按方向键时触发
- SB_PAGELEFT Scroll one page left.//按PageUp时或点击滑块左侧空白处触发
- SB_PAGERIGHT Scroll one page right.//按PageDown时或点击滑块右侧空白处触发
- SB_RIGHT Scroll to far right..// 按End键时触发
- SB_THUMBPOSITION Scroll to absolute position. The current position is specified by the nPosparameter.//拖拽滑块并释放时触发,此时nPos有效
- SB_THUMBTRACK Drag scroll box to specified position. The current position is specified by the nPosparameter.//拖拽滑块过程中触发,此时nPos有效
- void CCVTestDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- int Brightness = ((CSliderCtrl*)GetDlgItem(IDC_SLIDER1))->GetPos();//def :128
- int Contrast = ((CSliderCtrl*)GetDlgItem(IDC_SLIDER2))->GetPos();//def :64
- int Saturation = ((CSliderCtrl*)GetDlgItem(IDC_SLIDER3))->GetPos();//def :64
- int Hue = ((CSliderCtrl*)GetDlgItem(IDC_SLIDER4))->GetPos();//def :0
- CString str;
- if(GetDlgItem(IDC_SLIDER1) == pScrollBar)
- {
- //MessageBox(L"Slider1");
- switch(nSBCode)
- {
- case SB_PAGELEFT://影响鼠标点击一次滑块或用户按下PageUp和PageDown键,滑块移动的距离,由SetPageSize决定
- case SB_PAGERIGHT:
- case SB_LEFT://用户按下Home键触发
- case SB_RIGHT://用户按下End键触发
- case SB_LINELEFT://用户按下↑↓←→键时触发
- case SB_LINERIGHT://用户按下↑↓←→键时触发
- Brightness = ((CSliderCtrl*)GetDlgItem(IDC_SLIDER1))->GetPos();
- str.Format(L"%d",Brightness);
- SetDlgItemText(IDC_BRIGHT_EDIT,str);
- SetVideoPara(ChannelHandle[3], Brightness, Contrast, Saturation, Hue);
- break;
- case SB_THUMBPOSITION://鼠标拖拽滑块并释放时触发,此时nPos有效
- case SB_THUMBTRACK://鼠标拖拽滑块时触发,此时nPos有效
- //MessageBox(L"SB_THUMBPOSITION");
- Brightness = nPos;
- str.Format(L"%d",Brightness);
- SetDlgItemText(IDC_BRIGHT_EDIT,str);
- SetVideoPara(ChannelHandle[3], Brightness, Contrast, Saturation, Hue);
- break;
- default:
- break;
- }
- }
- CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
- }