TabControl

 

Contents

Name

TabControl

Remark

A tab control is used to switch displaying of related information in a dialog. TabControl class provides methods to add/delete tab items to display a group of controls.

Hierarchy

Examples

EX1

#include <Control.h>
#include <Dialog.h>
#define IDD_MY_DIALOG 1001
#define IDC_IMGOBJ_INFO 1101
#define IDC_IMGOBJ_INFO_TABS 1011
#define STR_DLG_RESOURCE_DLL  "MyDialog"
#define IMSG_INFO_IMAGE 0
#define IMSG_INFO_FINDINGS 1
#define IMSG_INFO_SELECTION 2
// shows a tab is used to switch the info displayed in an Edit box
class MyDialog : public Dialog
{
public:
    MyDialog() : Dialog(IDD_MY_DIALOG, STR_DLG_RESOURCE_DLL)
    {
    }
 
    int DoModal(HWND hParent = NULL)
    {
        InitMsgMap();
        int nRet = Dialog::DoModal(hParent);
        return nRet;
    }

protected:

        EVENTS_BEGIN
                ON_INIT( OnInitDialog )
                ON_TAB_SEL_CHANGE(IDC_IMGOBJ_INFO_TABS,OnInfoTabChange)
        EVENTS_END


        BOOL OnInitDialog()
        {
                m_editInfo = GetItem(IDC_IMGOBJ_INFO);    // edit box for info display
                m_tabInfo = GetItem(IDC_IMGOBJ_INFO_TABS); // a tab control to house this edit box
                m_tabInfo.InsertItem(IMSG_INFO_IMAGE,"Image Info");
                m_tabInfo.InsertItem(IMSG_INFO_FINDINGS, "Search Results");
                m_tabInfo.InsertItem(IMSG_INFO_SELECTION, "Selection Info");
                // move the edit control to be inside the client area of the tab control
                RECT rect;
                m_tabInfo.GetWindowRect(&rect);
                ScreenToClient(&rect);
                m_tabInfo.AdjustRect(FALSE, &rect);
                m_editInfo.MoveWindow(&rect);

                return TRUE;
        }
        BOOL OnInfoTabChange(Control ctrl)
        {
                int nType = m_tabInfo.GetCurSel();
                out_str(m_tabInfo.GetItemText(nType)); // print selected tab title
                return TRUE;
        }
        
protected:
        Edit            m_editInfo;
        TabControl      m_tabInfo;
};

bool DoMyDialog() 
{
    MyDialog myDlg;
    myDlg.DoModal( GetWindow() );
    return true;
}

header to Include

Control.h

Reference

Members

Name Brief Example
AdjustRect
DeleteAllItems
DeleteItem
GetCurSel
GetItemRect
GetItemText
InsertItem
SetCurSel
SetItemText
TabControl