首先自己写一个MySlider类。。该类继承 CSliderCtrl类。。
MySlider类响应LButtonDown消息来实现鼠标单击定位。。。
- void MySlider::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CSliderCtrl::OnLButtonDown(nFlags, point);
- CRect rectClient,rectChannel;
- GetClientRect(rectClient);
- GetChannelRect(rectChannel);
- int nMax = 0;
- int nMin = 0;
- GetRange(nMin,nMax);
- int nPos =
- (nMax - nMin)*(point.x - rectClient.left - rectChannel.left)/(rectChannel.right - rectChannel.left);
- SetPos(nPos);
- }
在主界面中:(***Dlg.h)
添加:#include "MySlider.h"
MySlider m_MySlider;
(***Dlg.cpp) 关联变量。。。
- void CCSliderPosDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CCSliderPosDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- DDX_Control(pDX,IDC_SLIDER1,m_MySlider);
- }
OnInitDialog()
{
m_MySlider.SetRange(0,100); //设置Slider的范围。。。
}