CapitolSoft Banner
Features
Tutorials
F.A.Q.s
Downloads
Articles
Open Architecture
Control Development Kit
RAD Foundation Class
Enhanced IntelliSense
Samples
Migration Center
RadVC and .NET
Testimonials
Links
Using RAD C++ Tab Control

A tab control acts like the dividers in a notebook or the labels on a group of file folders. By using a tab control, you can define multiple pages for the same area of a window or dialog box in your application.

Note: This article uses RadVC 1.3 or later

 

The Traditional Way
In traditional VC++ environment, you may have added tab support to your applications using Visual C++ resource editor. To do this, you first create an instance of the tab control object inside the dialog. In addition to this, you create a set of dialog templates that serve as the tab pages. If you use Microsoft Foundation Class (MFC), it provides a helper class called CPropertyPage that lets you "glue" the tab dialog templates to the property page / tab control.
 
Adding a tab control support to VC++/MFC apps in this way has some serious limitations. First, your tab control (MFC calls it property page) can be only added to classes that are derived from CDialog or CFormView class and thus can not be added to other Window classes (for example to a generic CWnd - derived class). Adding the support also isn't very simple either.. you need to override some functions in dialog class and write some code to do that.

Tab control can also be added to any Window class (e.g. a CWnd derived class), however VC++ does not provide any visual way to do so, everything has to be done by writing code. 

 
The RAD way
RadVC's tab control support does not have any of these limitations you normally face in traditional VC++ apps. First, when you use RadVC, you can add tab control to just any kind of windows, not only to a dialog windows. Also, any kind of control can qualify to be a tab page, it does not need to be derived from a CDialog class. What is more amazing, RadVC does not require you to write a single line of code to do all these complex stuff. RadVC's drag-n-drop programming technique will take care of these tough plumbing job for you.
 
What You Need
VC++ 6.0 with RadVC 1.3 or later
RAD C++ control CRTabCtrl. The control is part of the RadVC toolbox and can be found under "Win32" tab group. 
 
Tutorial
(1) Start a test project called TestRTabCtrl using RadVC's "New Project" option. This will open a blank form called "CForm1" in Developer Studio's client area.

(2) Click on the "Win32" tab of the RadVC toolbox and select the tool button "CRtabCtrl"

(3) Drop an instance of the tab control inside the form. 

 

(4) Now is the time to create tab pages for our control. In RadVC, any control can qualify to be a tab page. However, since we want our tab pages to "contain" other controls, so we will use RAD C++ controls as tab pages.

Creating a skeleton RAD C++ control is extremely easy. First right-click on anywhere on the RadVC toolbox, and select  the context menu item "Create New C++ Control". This will bring a dialog as shown below. In this dialog, change the name of the new RAD C++ control to something like "CTabPage1". Optionally, you can also change the bitmap of the new control by clicking on the "Edit.." button. 

One important note is that we will not check the checkbox "Add to Control Repository" in the dialog. This is so, because we want our tab pages to be part of our project only. Checking this checkbox would have placed the tab page in the RadVC control repository, which in turn makes it available to all VC++ projects.

 

Now click on the "OK" button. This will create a new control in your project and add a tool icon on the RadVC toolbox. In addition to this, RadVC will display a blank form inside Developer Studio's client area as shown below. 

(5) The blank form represents the control (CTabPage1) we have just created and will serve as our first tab page. You can now design this page by adding other controls from RadVC toolbox to this form (as shown below).

(6) Follow steps (4) and (5) to create additional pages for our tab control. Each time you create a tab page, you will see a corresponding icon on the RadVC toolbox. For this tutorial, we have created two tab pages called "CTabPage1" and "CTabPage2". They are shown by two icons "T1" and "T2" respectively on the RadVC toolbox.

(7) Now open the main form again and create two instances of the tab pages, we have just created. The main form will look something like this:

You shouldn't be worried about the location and sizes of the tab page control on the form. During runtime, the tab control will position and stretch the pages so that they all fit inside the client area of the tab control.

(8) To add the tab page to the tab control, simply right-click on the tab page icon and select "Add To > m_RTabCtrl" menu item as shown below. RadVC will add necessary code in the form's "Load" event handler. In case if the main form is a VC++ wizard - generated view class, RadVC will insert the code inside the view's "OnCreate(..)" message handler. 

 

After inserting the code, RadVC will open the form's implementation file (form1.cpp, in our case) and highlight the  "Form_Load" event handler. 

void CForm1::CreateControls()
{
   //{{AFX_CTRL_IMPL_START
   m_RTabCtrl1.Create(this, IDC_RTABCTRL1, CRect(14,7,238,217));
   m_TabPage11.Create(this, IDC_TABPAGE11, CRect(252,42,315,84));
   m_TabPage21.Create(this, IDC_TABPAGE21, CRect(252,105,315,154));
   //}}AFX_CTRL_IMPL_END
}


void CForm1::SetProperties() 
{
   //{{AFX_SETPROPS_IMPL_START
   Caption = _T("Form1");
   BackColor = RGB(192, 192, 192);
   //}}AFX_SETPROPS_IMPL_END
}


void CForm1::Form_Load() 
{
       m_RTabCtrl1.AddItem(&m_TabPage11);
}

 

 

(9) At this stage, you may want to modify the "AddItem" function call to specify the caption of the newly added tab page. The code will look something like this:

 

void CForm1::Form_Load() 
{
       m_RTabCtrl1.AddItem(&m_TabPage11, "My tab page 1");
}

(10) Follow steps (8) and (9) to add tab page 2 to the tab control.

Now build the project and run. 

 

 
Did you find this article useful? If so, please let us know. Also we need your ideas on new articles / tech tips etc.
Also: See the article on using Microsoft's Tabstrip ActiveX control here

 

 

[ Home ][ Order Now ][Feedback][ Contact Us ][ About CapitolSoft ]
[ Features ][ Tutorial ][ Samples ][ F.A.Q.s ][ Download ][ CDK ]