Hide

SftTabs/DLL 6.5 - Tab Control

Display
Print

Using SftTabs/DLL - C++/MFC Sample

The following code has been created using the SftTabs/DLL Wizard application:

/*- Tab Control Initialization Data --------------------------------------------*/

static const SFTTABS_CONTROL CtlInit = {
    SFTTABSSTYLE_MODERN_I,               /* tab style */
    1,                                   /* number of rows */
    0,                                   /* number of tabs per row (if fFixed) */
    0,                                   /* width of left margin */
    0,                                   /* width of right margin */
    FALSE,                               /* same width for all tabs */
    TRUE,                                /* Client area wanted */
    FALSE,                               /* allow multiline label text */
    TRUE,                                /* use with dialog */
    FALSE,                               /* use specified background color only for text */
    FALSE,                               /* scrollable tabs */
    FALSE,                               /* hide scroll buttons */
    FALSE,                               /* bold font for active tab wanted */
    FALSE,                               /* fill rows completely */
    NULL,                                /* scroll button bitmap */
    NULL,                                /* Dialog data associated with active tab */
    NULL,                                /* Dialog window handle associated with active tab */
    NULL,                                /* Frame, used as client area */
    TRUE,                                /* Tooltips wanted */
    FALSE,                               /* drop text if it doesn't fit */
    FALSE,                               /* conditional scroll buttons */
    BMBUTTONSTYLE_THEME_SCROLL2,         /* scroll button style */
    TRUE,                                /* display ... if truncated */
    TRUE,                                /* Flyby highlighting */
    TRUE,                                /* use client area colors in partially obscured frames */
    FALSE,                               /* scroll buttons on left side */
    -1,                                  /* row indentation */
    FALSE,                               /* don't show truncated pattern for clipped tab */
    FALSE,                               /* full size scroll buttons */
    TRUE,                                /* use themes on Windows XP */
    FALSE,                               /* use exact window region */
    FALSE,                               /* always show prefix _ */
    0,0,0,0,                             /* animation values */
    NULL,                                /* disabled button bitmap */
    TRUE,                                /* focus rectangle if the control has i/p focus */
    FALSE,                               /* TRUE if Close button wanted */
    FALSE,                               /* TRUE if Close button disabled */
    TRUE,                                /* TRUE if WM_CLOSE message wanted */
    FALSE,                               /* TRUE if Minimize, Restore, Close buttons are full size */
    SFTTABS_BUTTON_NEAR,                 /* scroll button alignment */
    SFTTABS_BUTTON_NEAR,                 /* Minimize, Restore, Close button alignment */
    FALSE,                               /* TRUE if Minimize button wanted */
    FALSE,                               /* TRUE if Minimize button disabled */
    FALSE,                               /* TRUE if Restore button wanted */
    FALSE,                               /* TRUE if Restore button disabled */
    NULL,                                /* Close, Minimize, Restore button bitmap */
    NULL,                                /* Close, Minimize, Restore disabled button bitmap */
    TEXT("Scroll Left/Up"),              /* scroll left button tooltip */
    TEXT("Scroll Right/Down"),           /* scroll button tooltip */
    TEXT("Close"),                       /* Close button tooltip */
    TEXT("Minimize"),                    /* Minimize button tooltip */
    TEXT("Restore"),                     /* Restore button tooltip */
    0,                                   /* custom modifications */
    0,                                   /* forced height/width depending on tab style - 0 to ignore */
    FALSE,                               /* switch tabs on button release (or down if FALSE) */
    FALSE,                               /* Rendering compatible with pre-6.0 */
    FALSE,                               /* don't display clientarea border - select styles only */
};

static const SFTTABS_TAB Tab0 = {   /*&One */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR,
};
static const SFTTABS_TAB Tab1 = {   /*&Two */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR,
};
static const SFTTABS_TAB Tab2 = {   /*T&hree */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR,
};
static const SFTTABS_TAB Tab3 = {   /*&Four */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR,
};
static const SFTTABS_TAB Tab4 = {   /*F&ive */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR,
};
static const SFTTABS_TAB Tab5 = {   /*&Six */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR,
};

/*------------------------------------------------------------------------------*/
/* This sample code can be used to initialize the tab control.                  */
/* This code is usually used in an OnInitDialog (WM_INITDIALOG), OnCreate       */
/* (WM_CREATE) or OnInitialUpdate member function of the tab control's parent   */
/* dialog or window.                                                            */
/*------------------------------------------------------------------------------*/

    int index;

    /* Associate the tab control created from the dialog       */
    /* resource with the C++ object.                           */
    m_Tab.SubclassDlgItem(IDC_TAB, this /* parent window */);

    /* You could use DDX/DDV instead and add the following     */
    /* line to the DoDataExchange function of the tab          */
    /* control's parent window (remove the //).                */
    // DDX_Control(pDX, IDC_TAB, m_Tab);

    /* 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

    hDC = ::GetDC(NULL);                 // Get a device context

    /* Create the font to be used for the tab control.         */

    height = MulDiv(8, ::GetDeviceCaps(hDC, LOGPIXELSY), 72);
                                         /* Convert point-size to pixels */
    m_Font.CreateFont(-height, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, 0, _T("MS Shell Dlg"));

    ::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("&One"));
    m_Tab.SetTabInfo(index, &Tab0);
    // If you don't want to attach a page to the tab, the following is optional
//  m_Tab.SetTabDialog(index, new an_object_based_on_CSftTabsPage(this)); // tab page

    index = m_Tab.AddTab(_T("&Two"));
    m_Tab.SetTabInfo(index, &Tab1);
    // If you don't want to attach a page to the tab, the following is optional
//  m_Tab.SetTabDialog(index, new an_object_based_on_CSftTabsPage(this)); // tab page

    index = m_Tab.AddTab(_T("T&hree"));
    m_Tab.SetTabInfo(index, &Tab2);
    // If you don't want to attach a page to the tab, the following is optional
//  m_Tab.SetTabDialog(index, new an_object_based_on_CSftTabsPage(this)); // tab page

    index = m_Tab.AddTab(_T("&Four"));
    m_Tab.SetTabInfo(index, &Tab3);
    // If you don't want to attach a page to the tab, the following is optional
//  m_Tab.SetTabDialog(index, new an_object_based_on_CSftTabsPage(this)); // tab page

    index = m_Tab.AddTab(_T("F&ive"));
    m_Tab.SetTabInfo(index, &Tab4);
    // If you don't want to attach a page to the tab, the following is optional
//  m_Tab.SetTabDialog(index, new an_object_based_on_CSftTabsPage(this)); // tab page

    index = m_Tab.AddTab(_T("&Six"));
    m_Tab.SetTabInfo(index, &Tab5);
    // If you don't want to attach a page to the tab, the following is optional
//  m_Tab.SetTabDialog(index, new an_object_based_on_CSftTabsPage(this)); // tab page

    m_Tab.SetControlInfo(&CtlInit);

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

    // If you are not using the sheet/page classes, remove the call to InitializeTabControl.
    // Initialize tab control.  Instead you have to make one of the tabs active using SetCurrentTab.
    InitializeTabControl(0, &m_Tab, NULL);
    // return FALSE; if this is a dialog's OnInitDialog member function

/*------------------------------------------------------------------------------*/
/* Page Implementation                                                          */
/*------------------------------------------------------------------------------*/

// Individual pages are implemented by creating a dialog with a dialog
// resource.  You can create each page as an object derived from CSftTabsPage
// (which is derived from CDialog).

// Once you have created the dialog resource, you can use ClassWizard to generate
// the implementation of the page object by deriving its new class from
// CDialog.  Because your object is really derived from CSftTabsPage,
// you have to manually edit all references to CDialog and change
// them to CSftTabsPage.

// When using ClassWizard to add new functions to this new class, make sure to
// change any reference to CDialog to use CSftTabsPage instead.

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