Hide

SftTabs/DLL 6.5 - Tab Control

Display
Print

Dialog Sample (C++/MFC)

This sample illustrates a simple tabbed dialog with nested tabs, some graphics, transition effects.

The source code is located at C:\Program Files (x86)\Softelvdm\SftTabs DLL 6.5\Samples\MFC\Dialog\Dialog.c or C:\Program Files\Softelvdm\SftTabs DLL 6.5\Samples\MFC\Dialog\Dialog.c (on 32-bit Dialogs versions).

/****************************************************************************/
/* SftTabs/DLL 6.5 - Tab Control for C/C++                                  */
/* Copyright (C) 1994, 2017  Softel vdm, Inc. All Rights Reserved.          */
/****************************************************************************/

#include "stdafx.h"
#include "dialog.h"

#include "maindlg.h"
#include "page1.h"                      // header files for all pages
#include "page2.h"
#include "page3.h"
#include "page4.h"
#include "page6.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

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

static const SFTTABS_CONTROL CtlInit = {
    SFTTABSSTYLE_MODERN_I,               /* tab style */
    2,                                   /* 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 */
    TRUE,                                /* bold font for active tab wanted */
    TRUE,                                /* 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_STD,                   /* scroll button style */
    FALSE,                               /* display ... if truncated */
    TRUE,                                /* Flyby highlighting */
    FALSE,                               /* 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 */
    TRUE,                                /* 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 */
    FALSE,                               /* 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 button tooltip */
    TEXT(""),                            /* scroll button tooltip */
    TEXT(""),                            /* Close button tooltip */
    TEXT(""),                            /* Minimize button tooltip */
    TEXT(""),                            /* 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 */
    SFTTABS_TABS_LEFT,                   /* alignment of tabs on all rows */
    SFTTABS_LAYOUT_DISTRIBUTE,           /* distribution of tabs on rows */
    0, 0,                                /* minimum and maximum number of rows for autoflow layout (none specified) */
    FALSE,                               /* reorderable tabs */
    FALSE,                               /* drag & drop */
};

static const SFTTABS_TAB Tab0 = {   /*The First One */
    SFTTABS_NOCOLOR, RGB(0,0,255),       /* background, foreground color */
    SFTTABS_NOCOLOR, RGB(0,0,255),       /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_LEFT, 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, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab1 = {   /*&Second */
    SFTTABS_NOCOLOR, RGB(255,0,0),       /* background, foreground color */
    SFTTABS_NOCOLOR, RGB(255,0,0),       /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_RIGHT, 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, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab2 = {   /*&Third */
    SFTTABS_NOCOLOR, RGB(128,128,0),     /* background, foreground color */
    SFTTABS_NOCOLOR, RGB(128,128,0),     /* 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, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab3 = {   /*F&ourth */
    SFTTABS_NOCOLOR, RGB(0,255,255),     /* background, foreground color */
    SFTTABS_NOCOLOR, RGB(0,255,255),     /* 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, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab4 = {   /*F&ifth */
    SFTTABS_NOCOLOR, RGB(0,0,128),       /* background, foreground color */
    SFTTABS_NOCOLOR, RGB(0,0,128),       /* 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, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab5 = {   /*Si&xth */
    SFTTABS_NOCOLOR, RGB(128,0,0),       /* background, foreground color */
    SFTTABS_NOCOLOR, RGB(128,0,0),       /* 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, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};

/////////////////////////////////////////////////////////////////////////////
// CMainDlg dialog


CMainDlg::CMainDlg(CWnd* pParent /*=NULL*/)
    : CSftTabsDialog(CMainDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CMainDlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    
    // Get the required bitmaps, icons
    m_SampleBitmap.LoadBitmap(IDB_BITMAP);/* Load bitmap */
    m_hIcon = AfxGetApp()->LoadIcon(1);
    m_hSampleIcon = AfxGetApp()->LoadIcon(IDI_ICON);
}

void CMainDlg::DoDataExchange(CDataExchange* pDX)
{
    CSftTabsDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMainDlg)
        // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMainDlg, CSftTabsDialog)
    //{{AFX_MSG_MAP(CMainDlg)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CMainDlg message handlers

BOOL CMainDlg::OnInitDialog()
{
    CSftTabsDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);   // Set big icon
	SetIcon(m_hIcon, FALSE);  // Set small icon

    int index;
    SFTTABS_TAB Tab;
    /* 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);

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

    index = m_Tab.AddTab(_T("The First One"));
    m_Tab.SetToolTip(index, _T("Demonstrates tabbing into and out of the tab page"));
    Tab = Tab0;
    Sft_SetPictureBitmap(&Tab.TabPicture, (HBITMAP) m_SampleBitmap.m_hObject);
    //Old Style (pre-6.0): Tab.graph.type = SFTTABS_GRAPH_BITMAP;
    //Old Style (pre-6.0): Tab.graph.item.hBitmap = (HBITMAP) m_SampleBitmap.m_hObject;
    m_Tab.SetTabInfo(index, &Tab);
    m_Tab.SetTabDialog(index, new CPage1(this)); /* tab page */

    index = m_Tab.AddTab(_T("&Second"));
    m_Tab.SetToolTip(index, _T("Demonstrates how an application can prevent tab switching"));
    Tab = Tab1;
    Sft_SetPictureIcon(&Tab.TabPicture, m_hSampleIcon);
    //Old Style (pre-6.0): Tab.graph.type = SFTTABS_GRAPH_ICON;
    //Old Style (pre-6.0): Tab.graph.item.hIcon = m_hSampleIcon;
    m_Tab.SetTabInfo(index, &Tab);
    m_Tab.SetTabDialog(index, new CPage2(this)); /* tab page */

    index = m_Tab.AddTab(_T("&Third"));
    m_Tab.SetToolTip(index, _T("This page is reset everytime you switch to it"));
    m_Tab.SetTabInfo(index, &Tab2);
    m_Tab.SetTabDialog(index, new CPage3(this)); /* tab page */

    index = m_Tab.AddTab(_T("F&ourth"));
    m_Tab.SetToolTip(index, _T("A page with private OK, Cancel, Next and Previous page buttons"));
    m_Tab.SetTabInfo(index, &Tab3);
    m_Tab.SetTabDialog(index, new CPage4(this)); /* tab page */

    index = m_Tab.AddTab(_T("F&ifth"));
    m_Tab.SetToolTip(index, _T("A page that has not yet been implemented"));
    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("Si&xth"));
    m_Tab.SetToolTip(index, _T("A page with nested tab controls and pages"));
    m_Tab.SetTabInfo(index, &Tab5);
    m_Tab.SetTabDialog(index, new CPage6(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
    InitializeTabControl(0, &m_Tab, NULL);

    // Update Tab2 to use transition effects
    {
        SFTTABS_TAB Tab;
        m_Tab.GetTabInfo(2, &Tab);
        Tab.animationStyleShow = SFTTABS_SLIDE_FROM_LEFT;
        Tab.animationTimeShow = 400;
        m_Tab.SetTabInfo(2, &Tab);
    }

    // Update Tab5 to use transition effects
    {
        SFTTABS_TAB Tab;
        m_Tab.GetTabInfo(5, &Tab);
        Tab.animationStyleShow = SFTTABS_EXPAND_CENTER;
        Tab.animationTimeShow = 400;
        m_Tab.SetTabInfo(5, &Tab);
    }

    {
        // Animate Window
        // Animation works on windows 98, 2000 or better only

        HMODULE hUser32 = GetModuleHandle(TEXT("USER32.DLL"));
        if (hUser32) {
            typedef BOOL (WINAPI* LPFNANIMATEWINDOW)(HWND, DWORD, DWORD);
            LPFNANIMATEWINDOW lpfnAnimateWindow;
            lpfnAnimateWindow = (LPFNANIMATEWINDOW)GetProcAddress(hUser32, "AnimateWindow");
            if (lpfnAnimateWindow) {
                CenterWindow();                
                lpfnAnimateWindow(m_hWnd, 300, AW_HOR_POSITIVE);
            }
        }
    }

    return FALSE; // if this is a dialog's OnInitDialog member function
}


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