VC slider usage

Source: Internet
Author: User

 

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.