Click here to Skip to main content
15,881,852 members
Articles / Desktop Programming

OutlookTabCtrl - Another Kind of Tab

Rate me:
Please Sign up or sign in to vote.
4.92/5 (49 votes)
16 Mar 2021Public Domain2 min read 745.6K   7.2K   203   92
This control is another kind of tab. Tabs are displayed as horizontal stripes and can be collapsed into buttons. Each tab is assigned its own window, which is shown when you click on the tab.

Image 1

Introduction

This control is another kind of tab. Tabs are displayed as horizontal stripes and can be collapsed into buttons located in a separate area. Each tab is assigned its own window, which is shown when you click on the tab. An additional button can be displayed in the button area. You can use it to show menu, for example.

The control is derived from CWnd and is a common control based on MFC. It is possible to put it on any window: main frame, dialog, etc.

Using the Code

To create the control and add elements to it, you can do the next steps:

C++
#include "OutlookTabCtrl.h"

OutlookTabCtrlEx<OutlookTabCtrlCustom1> m_TabCtrl;
CListCtrl m_List1, m_List2;

...

if( !m_TabCtrl.Create(this, WS_CHILD | WS_VISIBLE,CRect(10,10,100,200), ID_OutlookTabCtrl) )
    return -1;    // error.

// Create an ImageList with icons for tabs displayed as stripes.
m_TabCtrl.CreateStripeImage(NULL,IDB_STRIPE_NORMAL,IDB_STRIPE_DISABLE,true,24);
// Create an ImageList with icons for tabs displayed as buttons.
m_TabCtrl.CreateButtonImage(NULL,IDB_BUTTON_NORMAL,IDB_BUTTON_DISABLE,true,16);

// Create child controls.
if( !m_List1.Create(WS_CLIPCHILDREN | LVS_REPORT, CRect(0,0,0,0), &m_TabCtrl,ID_List1) ||
    !m_List2.Create(WS_CLIPCHILDREN | LVS_REPORT, CRect(0,0,0,0), &m_TabCtrl,ID_List2) )
    return -1;    // error.
m_List1.InsertColumn(0,"Mail",LVCFMT_LEFT,100);
m_List2.InsertColumn(0,"Calendar",LVCFMT_LEFT,100);

// Add child items in the m_TabCtrl.
if( !m_TabCtrl.AddItem(&m_List1,"Mail",0,0) ||
    !m_TabCtrl.AddItem(&m_List2,"Calendar",1,1) )
    return -1;    // error.

// Load state from registry.
if( !m_TabCtrl.LoadState(AfxGetApp(),"OutlookTabCtrl","State") )
    m_TabCtrl.PushVisibleItem();    // create default state.

m_TabCtrl.Update();

The OutlookTabCtrl class does not draw itself. To do this, inherit from the OutlookTabCtrl::Draw class and implement its functions. A pointer to OutlookTabCtrl::Draw must be passed to the control by calling the SetDrawManager function. The classes OutlookTabCtrlCustom1...OutlookTabCtrlCustom4 are ready-made implementations of the OutlookTabCtrl::Draw class. Each of them renders OutlookTabCtrl in its own style. The OutlookTabCtrlEx class helps you combine OutlookTabCtrl with the render class. For example, like this: OutlookTabCtrlEx<OutlookTabCtrlCustom2> ctrl; .

The OutlookTabCtrl::IRecalc interface sets the sizes of the areas in the control. The OutlookTabCtrl class has its own OutlookTabCtrl::IRecalc implementation. But you can also make your own implementation of the OutlookTabCtrl::IRecalc interface and pass a pointer to it in the control using the SetRecalcManager function.

There are also three additional classes: Ability, Notify, and ToolTip. The Ability class allows the user to select any tab. Notify informs about the occurrence of some event. ToolTip manages the creation of tooltips for tabs in button state. A pointer to the implementation of each of the classes must also be passed to OutlookTabCtrl.

Windows for all new added items should have the unique identifiers. Items can be in the state of a stripe or button. By default, an item is added as a stripe. The user should call the Update function to show the results that are set by functions DeleteItem, SetItemWindow, SelectItem, etc. You can hide an item (ShowItem) or block it (DisableItem). It is also possible to get the index of an item among all visible items (GetVisibleIndexByHandle) or in general among all items in the control (GetIndexByHandle). A control can save and load the position of its elements and their visibility from the registry or another source (LoadState/SaveState). This is only part of the possibilities. To learn more, take a look at the public interface of the OutlookTabCtrl class.

Good luck!

History

  • 4th October, 2007 - Original version posted
  • 11th October, 2007 - Fixed problem with addition Dialog as child control; added functions SetLayout and SetButtonsAlign for determination places of the control's areas
  • 17th December, 2008 - Just corrected some small errors
  • 16th March, 2021 - Improved sources and text of the article

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Software Developer
Canada Canada

Comments and Discussions

 
Questionuse this control in VS Win Form project ? Pin
BillWoodruff18-Mar-21 13:33
professionalBillWoodruff18-Mar-21 13:33 
AnswerRe: use this control in VS Win Form project ? Pin
Aleh Baradzenka18-Mar-21 13:56
Aleh Baradzenka18-Mar-21 13:56 
AnswerRe: use this control in VS Win Form project ? Pin
Aleh Baradzenka29-Mar-21 7:35
Aleh Baradzenka29-Mar-21 7:35 
GeneralRe: use this control in VS Win Form project ? Pin
BillWoodruff29-Mar-21 13:32
professionalBillWoodruff29-Mar-21 13:32 
GeneralMy vote of 5 Pin
Vincent Radio16-Mar-21 21:46
professionalVincent Radio16-Mar-21 21:46 
NewsNew version! Pin
Aleh Baradzenka18-Feb-21 13:23
Aleh Baradzenka18-Feb-21 13:23 
GeneralRe: New version! Pin
BillWoodruff18-Mar-21 13:35
professionalBillWoodruff18-Mar-21 13:35 
GeneralRe: New version! Pin
Aleh Baradzenka18-Mar-21 13:51
Aleh Baradzenka18-Mar-21 13:51 
Praiseit is amazing Pin
Southmountain24-Dec-20 8:39
Southmountain24-Dec-20 8:39 
GeneralRe: it is amazing Pin
Aleh Baradzenka18-Feb-21 11:56
Aleh Baradzenka18-Feb-21 11:56 
Questionrun error,"gettextextent" ,use vs2010 .thank you Pin
letiantxf5-Sep-14 0:34
letiantxf5-Sep-14 0:34 
AnswerRe: run error,"gettextextent" ,use vs2010 .thank you Pin
Aleh Baradzenka5-Sep-14 1:30
Aleh Baradzenka5-Sep-14 1:30 
GeneralRe: run error,"gettextextent" ,use vs2010 .thank you Pin
letiantxf7-Sep-14 3:57
letiantxf7-Sep-14 3:57 
GeneralRe: run error,"gettextextent" ,use vs2010 .thank you Pin
Aleh Baradzenka7-Sep-14 13:14
Aleh Baradzenka7-Sep-14 13:14 
GeneralRe: run error,"gettextextent" ,use vs2010 .thank you Pin
letiantxf12-Sep-14 3:55
letiantxf12-Sep-14 3:55 
GeneralRe: run error,"gettextextent" ,use vs2010 .thank you Pin
letiantxf12-Sep-14 4:00
letiantxf12-Sep-14 4:00 
GeneralRe: run error,"gettextextent" ,use vs2010 .thank you Pin
Aleh Baradzenka13-Sep-14 9:40
Aleh Baradzenka13-Sep-14 9:40 
GeneralRe: run error,"gettextextent" ,use vs2010 .thank you Pin
letiantxf16-Sep-14 21:35
letiantxf16-Sep-14 21:35 
QuestionTabs, splitter and windows layout Pin
Member 96655013-Apr-13 2:06
Member 96655013-Apr-13 2:06 
AnswerRe: Tabs, splitter and windows layout Pin
Aleh Baradzenka3-Apr-13 7:01
Aleh Baradzenka3-Apr-13 7:01 
Questionhow can I move the window to right of the listView(Mail, Calendar, Contacts...)?? Pin
chary_529-Sep-11 20:55
chary_529-Sep-11 20:55 
AnswerRe: how can I move the window to right of the listView(Mail, Calendar, Contacts...)?? Pin
Aleh Baradzenka30-Sep-11 11:08
Aleh Baradzenka30-Sep-11 11:08 
QuestionRe: how can I move the window to right of the listView(Mail, Calendar, Contacts...)?? Pin
chary_53-Oct-11 21:53
chary_53-Oct-11 21:53 
AnswerRe: how can I move the window to right of the listView(Mail, Calendar, Contacts...)?? Pin
Aleh Baradzenka4-Oct-11 0:19
Aleh Baradzenka4-Oct-11 0:19 
GeneralCan I use this control in .NET WinForm Application?? Pin
435sdfasfsddsf23-May-11 1:57
435sdfasfsddsf23-May-11 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.