Compartilhar via


Creating the Tab Control

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 the Add Member Variable Wizard to add a member variable of type CTabCtrl with the Control property. You can use this member to call CTabCtrl member functions.

  3. Map handler functions in the dialog class for any tab control notification messages you need to handle. For more information, see Mapping Messages to Functions.

  4. In OnInitDialog, 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 Create member function, possibly in OnInitialUpdate, possibly as early as the parent window's OnCreate 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 AfxOleInit.

These styles can be retrieved and set, after the control has been created, with respective calls to the GetExtendedStyle and SetExtendedStyle 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

Reference

Using CTabCtrl

Concepts

Controls (MFC)