Creating A Slider Control

1 -   Start Microsoft Visual C++.
2 - a/  Using the MFC AppWizard (exe), create a dialog project called ExoSlider.
b/ In Step 2 of 4 of the MFC AppWizard page, title your dialog as: Slider. Click Finish.
c/ Once you are back in the studio of Visual C++, delete the TODO line of text on the dialog.
If you are using Visual C++ 6, you might get a dialog that is too big for this exercise, you might just have to shrink it.
d/ Insert two static texts, one edit, and one slider controls, like the above graphic shows.
Identify the Edit box as: IDC_SLIDER_VALUE.
Identify the Slider control as IDC_SLIDER.
3 - a/ Right-click in the current dialog and choose ClassWizard...
b/ In the ClassWizard, from the Member Variables property sheet, double-click IDC_SLIDER to Add Member name m_Slider which is of Category Control and of the Variable Type CSliderCtrl. Click OK.
Add Member Variable for IDC_SLIDER_VALUE called m_SliderValue of Category Value and a CString Variable Type. Click OK.

Still in the MFC ClassWizard dialog box, click Message Maps. In the Object IDs list box, click CExoSliderDlg. In the list of Member Functions, click OnInitDialog. Click the Edit Code button.

We will set the range values for the slide control, namely the minimum and the maximum values.


d/ Implement the OnInitDialog() function as follows:
// TODO: Add extra initialization here
m_Slider.SetRangeMin(1, false);
m_Slider.SetRangeMax(100, false);
m_SliderValue = "1";
e/ Our application still needs to provide communication between the edit and the slider controls. Access the ClassWizard and associate WM_HSCROLL to CExoSliderDlg (Did I tell you that you could have made your slider control vertical by changing its position in the Properties dialog so in that case you could be choosing WM_VSCROLL in ClassWizard?).
Implement the OnHScroll() function as follows:
m_SliderValue.Format("%ld", nPos);

else {
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);

CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
On the main menu, click Build -> Set Action Configuration...
Double-click ExoSlider - Win32 Release.



Webmaster Copyright © 1999 FunctionX E-Mail