This documentation is archived and is not being maintained.

CScrollBar::Create 

Creates the Windows scroll bar and attaches it to the CScrollBar object.


virtual BOOL Create(
   DWORD dwStyle,
   const RECT& rect,
   CWnd* pParentWnd,
   UINT nID 
);

Parameters

dwStyle

Specifies the scroll bar's style. Apply any combination of scroll-bar styles to the scroll bar.

rect

Specifies the scroll bar's size and position. Can be either a RECT structure or a CRect object.

pParentWnd

Specifies the scroll bar's parent window, usually a CDialog object. It must not be NULL.

nID

The scroll bar's control ID.

Nonzero if successful; otherwise 0.

You construct a CScrollBar object in two steps. First, call the constructor, which constructs the CScrollBar object; then call Create, which creates and initializes the associated Windows scroll bar and attaches it to the CScrollBar object.

Apply the following window styles to a scroll bar:

  • WS_CHILD   Always

  • WS_VISIBLE   Usually

  • WS_DISABLED   Rarely

  • WS_GROUP   To group controls

// Example 1:
// Create a horizontal CScrollBar control as a child window of CMyView 
// class (a CView-derived class). The scroll bar is NOT visible until the
// call ShowScrollBar() is made. m_ScrollBar is of type CScrollBar class,
// and it is a member variable in CMyView class.
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
   if (CView::OnCreate(lpCreateStruct) == -1)
      return -1;

   VERIFY(m_ScrollBar.Create(
      SBS_HORZ | SBS_TOPALIGN | WS_CHILD, CRect(5, 5, 100, 30), this, 100));
   
   m_ScrollBar.ShowScrollBar();
   
   return 0;
}

// Example 2:
// Create a horizontal CScrollBar control as a child window of CMyView 
// class (a CView-derived class). m_ScrollBar is of type CScrollBar 
// class, and it is a member variable in CMyView class.
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
   if (CView::OnCreate(lpCreateStruct) == -1)
      return -1;

   VERIFY(m_ScrollBar.Create(
      SBS_HORZ | SBS_TOPALIGN | WS_CHILD | WS_VISIBLE, 
      CRect(5, 5, 100, 30), this, 100));

   return 0;
}
Show: