Creating the Tab Control

HomeOverviewSample

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 CTabCtrl 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 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:

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   Windows Common Controls and MFC Classes