Hide

SftTabs/DLL 6.5 - Tab Control

Display
Print

InitializeTabControl

Initializes a tab control in a tabbed window. Activates the specified tab and the associated page.

C++

protected:
    BOOL CSftTabsWindowSheet::InitializeTabControl(CWnd* pWnd, int iTab, CSftTabs* pTabCtl, CWnd* pFrame = NULL);

Parameters

pWnd

The CWnd based object describing the tab control's parent window.

iTab

The zero-based index of the tab to be made the active tab.

pTabCtl

A pointer to the tab control's CSftTabs based object.

pFrame

A pointer to a window's CWnd based object. This window will be used by SftTabs/DLL as client area for pages attached to the tab control. SftTabs/DLL uses this window's client area size and location as a replacement for the tab control's client area. The window described by pFrame may be hidden and/or disabled. If an application resizes or moves the frame window, the dependent page or Windows control also has to be resized by using the ResizePages function. Using this frame window, the client area of a tab control can be located anywhere in relation to the tab control even on a different dialog or window. This parameter may be NULL, in which case the tab control's client area is used for attached pages.

Returns

The return value is TRUE if the function was successful, otherwise FALSE is returned.

Comments

The InitializeTabControl function initializes a tab control in a tabbed window. Activates the specified tab and the associated page.

A tabbed window's tab control has to be initialized, which creates the page attached to the currently active tab. This is typically done in the OnCreate member function of the tabbed window.

When a tabbed window is destroyed, all attached CSftTabsWindowPage objects are automatically destroyed. However, any dynamically allocated CSftTabsWindowPage derived objects must be deleted (using the C++ delete operator) by the application.

Example

This example initializes the tab control of a tabbed window and activates the first tab:

int CSampleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;

    // Create a static control that we can place above the tab control.
    // This is just used to cover the parent window in that area.
    if (!m_Gap.Create(_T(""), SS_SIMPLE | WS_VISIBLE | WS_CHILD,
            CRect(0, 0, 0, 0), /* position */
            this))
        return -1;

#if !defined(TAB_CONTROL_WITH_CLIENTAREA)
    // Create a static control that we can use as a frame window for the tab control's
    // pages. This window is not visible and is just used to indicate the page position
    if (!m_Frame.Create(_T(""), SS_SIMPLE | WS_CHILD,
            CRect(0, 0, 0, 0), /* position */
            this))
        return -1;
#endif

    // Create the tab control
    if (!m_Tab.Create(
            WS_VISIBLE | WS_CHILD | /* Visible, child window */
            WS_CLIPCHILDREN | WS_TABSTOP | /* Clip child windows, tabstop */
            WS_GROUP, /* Group */
            CRect(0, 0, 0, 0), /* position */
            this, /* Parent window */
            IDC_TAB)) /* tab control ID */
        return -1;

    int index;

    /* Initialization is faster if we set redraw off */
    m_Tab.SetRedraw(FALSE);

    /* Create the font used for the tab control. */
    /* Fonts are owned by the application and have to remain */
    /* valid as long as the tab control uses the font. */
    int height; /* Height in pixels */
    HDC hDC; /* Device context */

    /* Create the font to be used for the tab control. */
    hDC = ::GetDC(NULL); /* Get a device context */
    height = MulDiv(12, ::GetDeviceCaps(hDC, LOGPIXELSY), 72);/* Convert ...
    m_Font.CreateFont(-height, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, 0, _T("Arial"));
    ::ReleaseDC(NULL, hDC); /* Release device context */
    m_Tab.SetFont(&m_Font, FALSE); /* Set tab control font */

    /* We are using new features */
    m_Tab.SetVersion(SFTTABS_6_5);

    index = m_Tab.AddTab(_T("&Listbox"));
    m_Tab.SetToolTip(index, _T("ToolTip for the ListBox tab"));
    m_Tab.SetTabInfo(index, &Tab0);
    m_Tab.SetTabWindowPage(index, &m_ListBox); /* tab page */

    index = m_Tab.AddTab(_T("&Edit Control"));
    m_Tab.SetTabInfo(index, &Tab1);
    m_Tab.SetTabWindowPage(index, &m_Edit); /* tab page */

    index = m_Tab.AddTab(_T("&Other Listbox"));
    m_Tab.SetToolTip(index, _T("ToolTip for the Other ListBox tab"));
    m_Tab.SetTabInfo(index, &Tab2);
    m_Tab.SetTabWindowPage(index, &m_OtherListBox); /* tab page */

    m_Tab.SetControlInfo(&CtlInit);

    // Make sure to turn redraw back on
    m_Tab.SetRedraw(TRUE);
    m_Tab.InvalidateRect(NULL, TRUE);

#if defined(TAB_CONTROL_WITH_CLIENTAREA)
    // Initialize tab control
    InitializeTabControl(this, 0, &m_Tab, NULL);
#else
    // Initialize tab control. An invisible, disabled frame window is used to ...
    InitializeTabControl(this, 0, &m_Tab, &m_Frame);
#endif

    // Mark the view as a main, tabbed window (so accel. keys work) by registering it.
    SftTabs_RegisterWindow(m_hWnd);

    return 0;
}

See Also C/C++ API | C++ Classes | Notifications


Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.