Visual C++ and MFC Fundamentals Chapter 17: Track-Based Controls
return TRUE; // return TRUE unless you set the focus to a control
}
- Test the application and return to MSVC
17.3.5..Slider Events........................................................................................
On its own, the slider controls can send three notification messages:
?? The NM_OUTOFMEMORY message is sent when the slider has run out of
memory and could not complete a task
?? The NM_RELEASECAPTURE message is sent when the user releases the
mouse on the slider
?? The NM_CUSTOMDRAW message is used if you want to draw something on
the slider or you want to customize the appearance of the slider beyond what
Visual C++ proposes
For its functionality, the slider highly relies on its parent. When the user clicks the thumb
or any part of the slider, which causes it to slide, a scroll event is fired. If the slider is
horizontal, the CWnd::OnHScroll() event is sent. If the slider is vertical, the
CWnd::OnVScroll() event is sent.
Practical Learning: Scrolling a Slider Control
- Change the OnPaint() event of the dialog class as follows:
void CCarInventory1Dlg::OnPaint()
{
int CurPos = m_CarSlider.GetPos() - 1;
CBitmap Bmp;
Bmp.LoadBitmap(Car[CurPos].CarPicture);
m_Make.Format("%s", Car[CurPos].Make);
m_Model.Format("%s", Car[CurPos].Model);
m_Year.Format("%d", Car[CurPos].CarYear);
m_Doors.Format("%d", Car[CurPos].Doors);
m_Picture.SetBitmap(Bmp);
UpdateData(FALSE);
...
}
2. Using either the ClassWizard (MSVC 6) or the Messages button , for the dialog,
generate the WM_HSCROLL message and implement it as follows:
void CSlider1Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
Invalidate();
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
- Test the application