Click here to Skip to main content
15,884,177 members
Articles / Desktop Programming / MFC
Article

Simple Tab Control For Visual C++

Rate me:
Please Sign up or sign in to vote.
4.16/5 (27 votes)
14 Oct 20041 min read 286.6K   13.7K   61   47
Using this Tab control the user can manage their dialogs in different Tab panes.

Image 1

Introduction

This is my first article for the CodeProject, so please excuse me if it is really hard to understand. But I am always ready to help you on this.

Using this simple Tab control you can manage your panes separately. The most interesting thing is that you do not need to concentrate separately on your Tab control. Create your tab windows as normal dialog boxes, then you can link those dialogs to the Tab control by simply using the code given below. Set your dialog properties as follows: (dialogs to be displayed as tab panes)

  • Border: None
  • Title Bar: False
  • System Menu: False
  • Style: Popup

The client edge and other edge styles can be set according to your needs. Those edge styles will be a reflection of your tab pane.

// In your main dialog (where your Tab Control is) in OnInitDialog 
// write these simple lines to add your dialogs to Tab Panes.
   p1 = new CTabPageOne(); //p1 is a pointer to CTabPageOne (Dialog Box) 
   p1->Create(IDD_DIALOG_PAGE1,m_ctrlTAB.GetWindow(IDD_DIALOG_PAGE1));
   p2 = new CTabPageTwo(); //p1 is a pointer to CTabPageOne (Dialog Box) 
   p2->Create(IDD_DIALOG_PAGE2,m_ctrlTAB.GetWindow(IDD_DIALOG_PAGE2));

Add the above dialog boxes to your Tab control. Your Tab control is created from CibTabCtrl.

m_ctrlTAB.AddTabPane("Tab Intro",p1);
m_ctrlTAB.AddTabPane("My Tab Pages",p2);

There are two more things to do. That is, add the OnMove event to your main dialog box using your class wizard:

void CTabDlg::OnMove(int x, int y)
{
    m_ctrlTAB.OnMove(x,y);
}

Now, add the OnShowWindow event to your main dialog box using your class wizard.

void CTabDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
    CDialog::OnShowWindow(bShow, nStatus); 
    m_ctrlTAB.SetDefaultPane(1);
}

Foooo... That's all you have to do. Now you can run and see your output. Hope it works for you!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Sri Lanka Sri Lanka
I am working as a Tech Lead. I love VC++.
I am trying to get into new technologies coming with VC++ and also in other areas too.

Currently I am working in C# .Net as well...

Now I have sound knowledge in C# as well as in VC++.

Comments and Discussions

 
AnswerRe: how to access a control in the tab from Main Dialog Pin
Holywood0724-Feb-05 4:27
Holywood0724-Feb-05 4:27 
AnswerRe: how to access a control in the tab from Main Dialog Pin
yingpf30-Dec-05 2:53
yingpf30-Dec-05 2:53 
QuestionOnMove CDialog hides -> is there any Workaroud? Pin
kim.david.hauser29-Nov-04 8:53
kim.david.hauser29-Nov-04 8:53 
AnswerRe: OnMove CDialog hides -> is there any Workaroud? Pin
kim.david.hauser29-Nov-04 9:13
kim.david.hauser29-Nov-04 9:13 
JokeRe: OnMove CDialog hides -> is there any Workaroud? Pin
Sasan12-May-06 21:36
Sasan12-May-06 21:36 
Questionhow to create tab in mdi(no mdi tab) Pin
vc-programmer-28-Oct-04 23:51
vc-programmer-28-Oct-04 23:51 
GeneralVertical Style not supported Pin
freddycam27-Oct-04 21:56
freddycam27-Oct-04 21:56 
Generalstrange behaviour in your demo Pin
BoscoW18-Oct-04 1:09
BoscoW18-Oct-04 1:09 
wen i drag and drop the dialog (your demo) over an other windo i can't see it because it gets atomaticali in the backgroud !!!!

it's not a normal behaviour , is it on purpose ? and for wath ?

try draging your dialog on your desk and then in front of an open browser windo (it moves but you will see it only wenn you drag it left or right to the end of the browser windoe than you can seee that it is dragged behind it )

hope you understadn the problem (sorry for my bad english)
GeneralInvalid demo file Pin
Smitha Nishant17-Oct-04 22:27
protectorSmitha Nishant17-Oct-04 22:27 

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.