Share via


Creating the Tab Control

OverviewSample

How the tab control is created depends on whether you are using the control in a dialog box or creating it in a nondialog window.

To use CTabCtrl directly in a dialog box

  1. In the dialog editor, add a Tab Control to your dialog template resource. Specify its control ID.

  2. Use ClassWizard to add a member variable of type with the Control property. You can use this member to call CTabCtrl member functions.

  3. Use ClassWizard to map handler functions in the dialog class for any tab control notification messages you need to handle.

  4. In , set the styles for the CTabCtrl.

To use CTabCtrl in a nondialog window

  1. Define the control in the view or window class.

  2. Call the control's member function, possibly in , possibly as early as the parent window's handler function (if you're subclassing the control). Set the styles for the control.

After the CTabCtrl object has been created, you can set or clear the following extended styles:

  • TCS_EX_FLATSEPARATORS   The tab control will draw separators between the tab items. This extended style only affects tab controls that have the TCS_BUTTONS and TCS_FLATBUTTONS styles. By default, creating the tab control with the TCS_FLATBUTTONS style sets this extended style.

  • TCS_EX_REGISTERDROP   The tab control generates TCN_GETOBJECT notification messages to request a drop target object when an object is dragged over the tab items in the control.

    Note   To receive the TCN_GETOBJECT notification, you must initialize the OLE libraries with a call to .

These styles can be retrieved and set, after the control has been created, with respective calls to the and member functions.

For instance, set the TCS_EX_FLATSEPARATORS style with the following lines of code:

DWORD dwExStyle= m_tabCtrl.GetExtendedStyle();
m_tabCtrl.SetExtendedStyle(dwExStyle | TCS_EX_FLATSEPARATORS);

Clear the TCS_EX_FLATSEPARATORS style from a CTabCtrl object with the following lines of code:

DWORD dwExStyle= m_tabCtrl.GetExtendedStyle();
m_tabCtrl.SetExtendedStyle(dwExStyle & ~TCS_EX_FLATSEPARATORS);

This will remove the separators that appear between the buttons of your CTabCtrl object.

See Also   Windows Common Controls and MFC Classes