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 in ApplicationProgramIs widely used, 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) initializeCodeBool cmy601dlg: oninitdialog (), and then add the corresponding attribute. 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.