您的位置:首页 > 其它

[VC/MFC]滑动动条控件Slider的用法

2012-08-23 10:59 441 查看
在MFC中滑动条(CSliderCtrl)是个常用的控件,用法如下:
主要要方法有:

1、设置、取得滑动范围:

void SetRange( int nMin, int nMax, BOOL bRedraw = FALSE );
void GetRange( int& nMin, int& nMax ) const;

2、设置、取得按下左右箭头滑动间隔:

int SetLineSize( int nSize );
int GetLineSize( ) const;

3、设置、取得按下PgUp、PgDown时滑动间隔:

int SetPageSize( int nSize );
int GetPageSize( ) const;

4、设置、取得滑块位置:

void SetPos( int nPos );
int GetPos( ) const;

5、设置滑动条刻度的频度:

void SetTicFreq( int nFreq );

实例:

在对话框中放一个Slider控件,添加相应的Ctrl型变量为m_slider。在对话框初始化函数OnInitDialog()中添加:

BOOL CDlgSetup::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here

m_slider.SetRang(0,100);//设置滑动范围

m_slider.SetTicFreq(10);//每10个单位画一刻度
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

Slider控件本身并没有响应滑动的消息函数,但可以通过主窗体的OnHScroll()响应。在类向导中为对话框添加WM_HSCROLL消息,在响应函数中添加:

void CDlgSetup::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CSliderCtrl *pSlidCtrl=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
m_int=pSlidCtrlHue->GetPos();//取得当前位置值
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

//m_int 即为当前滑块的值。

本篇文章来源于 3SDN 转载请以链接形式注明出处 网址:http://www.3sdn.net/programing/vc/2008-12-01/107.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: