Slider control in VC ++

Source: Internet
Author: User
Sliding controls are one of the most commonly used controls in Windows. Generally, it is composed of a slider, a slider, and an optional scale. You can move the slider to display the corresponding value in the corresponding control. Generally, there must be a label control or edit box control near the sliding control to display the corresponding value. Sliding controls are widely used in applications, as can be seen in desktop properties. For this reason, let's take a look at its implementation methods.

(1) create a dialog box document project in VC ++ 6.0.

(2) Open the resource manager, place an EDIT control in the dialog box, and put a Slider control next to it. The basic framework has been completed.

(3) Right-click the Slider control and select "create Class Wizard" to define a variable m_Slider for the Slider control, with the type of CSliderCtrl.

(4) In the code BOOL CMy601Dlg: OnInitDialog () initialized in the dialog box, add the corresponding attributes. The following are common attribute setting functions:

* GetRange and SetRange Functions

Used to query and set the value range of the slider. The default value is 0 ~ 100. The function is defined as follows:

Void GetRange (int & nMin, int & nMax) const;
Void SetRange (int nMin, int nMax, BOOL bRedrGETaw = FALSE );

* GetPos and SetPos Functions

Used to query and set the current value of the slide bar. The function is defined as follows:

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

* GetLineSize, SetLineSize Function

Used to query and set the slider movement when you click the right or left arrow. The default value is 1. The function is defined as follows:

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

* GetPageSize, SetPageSize Function

It is used to query and set the slider and block movement volume. The block movement Volume refers to the Movement volume of the slider when PgUp or PgDown is pressed. The function definition form is as follows:

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

* SetTicFreq Function

Used to set the frequency of the slider scale. It is a function in one unit by default. The function is defined as follows:

Void SetTicFreq (int nFreq );

* SetTic Functions

Sets the scale at the specified position. By default, Windows scales evenly. The function is defined as follows:

BOOL SetTic (int nTic );

* ClearTics Functions

Used to clear all scales. The function is defined as follows:

Void ClearTics (BOOL bRedraw = FALSE );

We write the following statement during initialization:

M_Slider.SetRange (-100,100 );
M_Slider.SetTicFreq (10 );

That is, the range is-100 to 100, and the scale is one for every 10 units.

(5) Now we add the event process code.

Select the "event" of the Slider, select the first process (NM_CUSTOMDRAW), and then add the following code:

Void CMy601Dlg: OnCustomdrawSlider1 (NMHDR * pNMHDR, LRESULT * pResult)
{
UpdateData (TRUE );
M_Int = m_Slider.GetPos ();
UpdateData (FALSE );
* PResult = 0;
}

M_Int is a variable of the INT type defined in the EDIT control. Now our editing is complete.

(6) Compile and run the program. You can easily use the Slider control.

 

The above code is successfully debugged on Windows2000, VC ++ 6.0/VC ++. net.

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.