All controls are created on the same path;
Step 1: Create a csliderctrl Class Object in. h;
Csliderctrl m_ctrlslider;
Step 2: Initialize the control using the void cmydlg: dodataexchange (cdataexchange * PDX) function in. cpp; // initialize the control
Void cmydlg: dodataexchange (cdataexchange * PDX)
{
// This function is used to exchange data between controls and class members.
Cdialog: dodataexchange (PDX );
// Special slider
Ddx_control (PDX, idc_slider1, m_ctrlslider );
}
Step 3: Set initialization in the bool cmydlg: oninitdialog () function; // set Initialization
Bool cmydlg: oninitdialog ()
{
Cdialog: oninitdialog ();
.........
M_ctrlslider.setrange (0,100); // you can specify the maximum and minimum values of the slider position.
M_ctrlslider.setpos (30); // you can specify the default position of the slider.
}
Step 3: Add event processing functions;
After initialization, add an event processing function to obtain the corresponding data when adjusting the slider position;
Add function declaration in 1.h
Afx_msg void onnmcustomdrawslider1 (nmhdr * pnmhdr, lresult * presult );
2. Add a message:
Begin_message_map (cmydlg, cdialog)
.........
On_notify (nm_customdraw, idc_slider1, onnmcustomdrawslider1)
.........
3. function definition; // This function is called through (2) when the slider is adjusted;
// Main Window Slider
Void cmydlg: onnmcustomdrawslider1 (nmhdr * pnmhdr, lresult * presult)
{
Int NPOs = m_ctrlslider.getpos (); // obtain the current position of the slider
// Make another edit box to display the adjusted data;
Cstring STR = _ T ("");
Str. Format (_ T ("% d %"), NPOs );
Setdlgitemtext (idc_edit13, STR );
}
Complete