Csliderctrl is a common control in MFC. Its usage is as follows:
The main methods are as follows:
1. Set and obtain the sliding range:
Void setrange (INT Nmin, int Nmax, bool bredraw = false );
Void getrange (Int & Nmin, Int & Nmax) const;
2. Set and obtain the sliding interval by pressing the left and right arrows:
Int setlinesize (INT nsize );
Int getlinesize () const;
3. Set and obtain the sliding interval when pressing pgup and pgdown:
Int setpagesize (INT nsize );
Int getpagesize () const;
4. Set and obtain the slider position:
Void setpos (INT NPOs );
Int getpos () const;
5. Set the frequency of the slider scale:
Void setticfreq (INT nfreq );
Instance:
In the dialog box, place a slider control and add the corresponding CTRL variable m_slider. In the initialization function oninitdialog () in the dialog box, add:
Bool cdlgsetup: oninitdialog ()
{
Cdialog: oninitdialog ();
// Todo: add extra initialization here
M_slider.setrang (0,100); // you can specify the sliding range.
M_slider.setticfreq (10); // draw a scale for every 10 units
Return true; // return true unless you set the focus to a control
// Exception: OCX property pages shold return false
}
The slider control does not respond to the sliding message function, but it can respond through the onhscroll () of the main form. In the Class Wizard, add the wm_hscroll message to the dialog box and add the following in the response function:
Void cdlgsetup: onhscroll (uint nsbcode, uint NPOs, cscrollbar * pscrollbar)
{
// Todo: add your message handler code here and/or call default
Csliderctrl * ps1_ctrl = (csliderctrl *) getdlgitem (idc_slider1 );
M_int = ps1_ctrlhue-> getpos (); // get the current position value
Cdialog: onhscroll (nsbcode, NPOs, pscrollbar );
}
// M_int indicates the value of the current slider.
Link: http://dragoon666.blog.163.com/blog/static/107009194201011159522611/