在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
posted on 2009-05-06 16:19
李陽 閱讀(26160)
評論(6) 編輯 收藏 引用