11. DEMONSTRATION OF SLIDER CONTROL
Step 2:-Select a project tab from new window and from that select MFC application wizard [exe] option and give a project name as Sliders and click ok.
Step 3:-
Þ MFC Application wizard window is appeared.
Þ Select dialog based default settings in step 1, click next.
Þ Select default settings from step 2 to step 6 and click finish.
Þ New projects information on window will appear and click ok.
Step 4:-Add a slider, an edit box, two labels (static box) and label the controls.
Step 5:-Goto class wizard -> new member variable -> m_slider -> category control for Slider and for edit box add the member variables as m_text and click ok.
Step 6:-Initialize the slider control, i.e. the slider can take extreme left position and extreme right position. Set the range from 1 to 100 using the CSlider SetRangeMin() and SetRangeMax() methods. For that go to class view tab -> CSliderDlg -> OnInitDialog() method and write the following code:
BOOL CSliderDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_slider.SetRangeMin(1, false);
m_slider.SetRangeMax(100, false);
m_text = ‘1’;
UpdateData (false);
Step 7:-Goto class wizard -> object ID’S -> CSliderDlg -> messages -> WM_HSCROLL double click it -> OnHScroll() -> ok.
void CSliderDlg::OnHScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if(nSBCode == SB_THUMBPOSITION)
{
m_text.Format(“%ld”, nPos);
UpdateData (false);
}
else
{
CDialog::OnHScroll (nSBCode, nPos, pScrollBar);
}
}
OUTPUT
No comments:
Post a Comment