Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 18: Progress-Based Controls Visual C++ and MFC Fundamentals


// TODO: Add your control notification handler code here
int Min, Max;

m_Scroller.GetScrollRange(&Min, &Max);
m_MinValue.Format("%d", Min);
m_MaxValue.Format("%d", Max);

UpdateData(FALSE);
}

Once the control has been created and it has the minimum and maximum values set, its
thumb would appear in the minimum position. If you want it to assume another position
within the range, call the CScrollBar::SetScrollPos() method. Its syntax is:

int SetScrollPos(int nPos, BOOL bRedraw = TRUE);

The nPos argument hold the value of the new position for the thumb. This value must be
between the nMinPos and the nMaxPos values of the SetScrollRange() method. You
may need the control to be redraw after this value has been set to reflect the new change,
which is the default behavior. If you do not want the control the control to be redrawn,
pass the FALSE value as a second argument.

Here is an example:

BOOL CScrollingDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
Scroller->Create(WS_CHILD | WS_VISIBLE |
SBS_VERT | SBS_LEFTALIGN | SBS_RIGHTALIGN,
CRect(200, 15, 240, 148), this, 0x16);

Scroller->SetScrollRange(12, 248);
Scroller->SetScrollPos(165);

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Free download pdf