Sei sulla pagina 1di 2

Visual C++ Tutorial - Slider Control

http://www.functionx.com/visualc/classes/slider1.htm

Creating A Slider Control


Home

12a/ b/ c/

Start Microsoft Visual C++. Using the MFC AppWizard (exe), create a dialog project called ExoSlider. In Step 2 of 4 of the MFC AppWizard page, title your dialog as: Slider. Click Finish. 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. 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. Right-click in the current dialog and choose ClassWizard... 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/

3-

a/ b/

c/

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"; UpdateData(FALSE);

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?).

1 of 2

15-06-2011 10:02

Visual C++ Tutorial - Slider Control

http://www.functionx.com/visualc/classes/slider1.htm

Implement the OnHScroll() function as follows: if(nSBCode == SB_THUMBPOSITION) { m_SliderValue.Format("%ld", nPos); UpdateData(false); } 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.

Download
CyberLock-Electronic Lock Complete access control for doors, padlocks, gates, and cabinets. WPF,Silverlight, WinForms Ribbon, UI Virtualizing Wrap panel, TreeListView, Tabstrip, & more Time Attendance System Get Quality Efficient Biometric Systems @ Digital Devices.Call Now!
www.videx.com

www.binarymission.co.uk digitaldevicesindia.com/09845249619

Webmaster

Copyright 1999 FunctionX

E-Mail

2 of 2

15-06-2011 10:02

Potrebbero piacerti anche