Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


ScrInfo.nMax = 368;
ScrInfo.nPage = 2;
ScrInfo.nPos = 186;

m_Scroller.SetScrollInfo(&ScrInfo);

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

If a scroll bar has already been initialized, even it was not initialized using the
SetScrollInfo() method, to get information about its values, you can call the
CScrollBar::GetScrollInfo(). Its syntax is:

BOOL GetScrollInfo(LPSCROLLINFO lpScrollInfo, UINT nMask);

This method returns a SCROLLINFO value that holds the values of the scroll bar. The
possible values of the SCROLLINFO::fMask member variable are:

Value Description

SIF_RANGE Used to retrieve the minimum and the maximum values

SIF_POS

Used to retrieves the current position of the scroll thumb.
The thumb should not be scrolling when the
GetScrollInfo() method is called to get the value
associated with this mask

SIF_PAGE

Used to retrieve the page size to scroll when using the
control

SIF_TRACKPOS

Used to retrieve the current position of the thumb while
the user is scrolling
SIF_ALL Used to retrieve all above values

Practical Learning: Using Scroll Bars



  1. Using the OnInitDialog() event, set the range of each scroll bar to (0, 255) and set
    their initial values to 192


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

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
m_ScrollRed.SetScrollRange(0, 255);
m_ScrollRed.SetScrollPos(63);
m_ScrollGreen.SetScrollRange(0, 255);
m_ScrollGreen.SetScrollPos(63);
m_ScrollBlue.SetScrollRange(0, 255);
m_ScrollBlue.SetScrollPos(63);
return TRUE; // return TRUE unless you set the focus to a control
}
Free download pdf