Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


In the same way, you can set the Align property to a Bottom/Right value to keep the
bottom border for a horizontal scroll bar or the right border for a vertical scroll bar and
resize them to the default height or width respectively.

If you are programmaticall creating the control, to resize a horizontal scroll bar to assume
the default height known to the operating system combine the SBS_HORZ with the
SBS_TOPALIGN and possibly the SBS_BOTTOMALIGN values to its style. On the
other hand, to get the default width of a vertical scroll bar, besides the SBS_VERT style,
add the SBS_LEFTALIGN and the SBS_RIGHTALIGN values:

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, 320, 148), this, 0x16);

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

We mentioned already that the operating system keeps a default height for a horizontal
scroll bar and a default width for a vertical scroll bar. To get these default values and
apply them to your scroll bar control, call the GetSystemMetrics() function and pass it
either the SM_CXVSCROLL or the SM_CXHSCROLL value. Then add the value to
the x member of the rect argument for the Create() method. Here is an example:
Free download pdf