VC slider用法

來源:互聯網
上載者:User

 

在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 即為當前滑塊的值。

 

原文連結:http://dragoon666.blog.163.com/blog/static/107009194201011159522611/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.