Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Environment: VC6 SP3, NT4, Windows 2000 Pro, Windows 2000 Server

Firstly add the CMyTabCtrl.cpp and CMyTabCtrl.h to your project.

Using Visual Studio add a CTabCtrl control to your dialog. Add a member variable for this control as a CMyTabCtrl type not a simple CTabCtrl. CMyTabCtrl is derived from CTabCtrl.

You can simply add a CTabCtrl member variable and manually edit the file to become CMyTabCtrl

Now create dialogs for every page you require. These must be child dialogs with no border. Any controls here in these dialogs are handled by their own class.

Create a Class for each dialog. In the example these are CTabOne, CTabTwo and CTabThree.

In the CmyTabCtrl constructor you must add a new for each page. Also in the Init function you must specify all tab dialogs to hide all but one

In this example the OnLButtonDown message handler is used to show and hide the various dialogs. The page is managed with a variable m_tabCurrent which holds the value of selected pages.

In the main app dialogs OnInitDialog message handler add the tabs you require for your dialog. In this example these are Tab One, Tab Two and Tab Three.

Functionality for the left and right cursor keys to select the tabs can be added in the CMyTabCtrl class.

 m_tabPages[0]=new CTabOne;
 m_tabPages[1]=new CTabTwo;
 m_tabPages[2]=new CTabThree;


 for(int nCount=0; nCount < m_nNumberOfPages; nCount++){
  delete m_tabPages[nCount];

void CMyTabCtrl::Init()

 m_tabPages[0]->Create(IDD_TAB_ONE, this);
 m_tabPages[1]->Create(IDD_TAB_TWO, this);
 m_tabPages[2]->Create(IDD_TAB_THREE, this);



void CMyTabCtrl::SetRectangle()
 CRect tabRect, itemRect;
 int nX, nY, nXc, nYc;

 GetItemRect(0, &itemRect);


 m_tabPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
 for(int nCount=1; nCount < m_nNumberOfPages; nCount++){
  m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);

// CMyTabCtrl message handlers

void CMyTabCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
 CTabCtrl::OnLButtonDown(nFlags, point);

 if(m_tabCurrent != GetCurFocus()){

The Dialog Showing, Hiding and Drawing code is from the C++ Forum On this site. It was posted by someone whom I don't have name for.

If it was you then please let me know and I will have your name added

I hope this code is of some use. It has helped me to develop much more complex dialogs.


Download demo project - 18 Kb
Download source - 2 Kb


  • edit box data transfer from one tab to another

    Posted by yuvaraj on 09/08/2016 08:07pm

    how to transfer editbox data from one tab control to another tab ? cant possible to set data from one tab to another? anyone can have plz send me. tried so many ways but no solution

  • Bad example if you want to access Controls from different Tabs

    Posted by hoschy on 07/18/2006 12:36pm

    It works quite nice, BUT I want to access lets say a editcontrol in one tab from the main dialog, its just not possible. ItB4s better to use the main Dialog for Initialization and stuff, this way you can access all editcontrols in the main Dialog. And this is what most users want i think.

  • Resolution to Strange behaviour on keypress

    Posted by ksumit on 04/09/2004 11:11am

    All that needs to be done is add OnCancel() event handlers for all the child dialogs/forms.And within this get the Parent dialog pointer and distroy the dialog. For key press (enter) have an event handler OnOK for each child dialogs.

  • Another way to get data from Tab to Main Dialog

    Posted by pkpk on 04/01/2004 03:15am

    I ran across this on Google Groups it works well: In your tab class code use the following line to get a hook to the main dialogs member variables and functions CMyTabExampleDlg* pMainWnd = (CMyTabExampleDlg*) AfxGetMainWnd(); pMainWnd will then give you access to main dialog

  • Strange behaviour on keypress (enter-/esc key)

    Posted by Stoodent on 03/26/2004 05:06pm

    If you put the focus to any control whithin the tab area so that the OK or CANCEL button is not selected and you hit the enter key the tab page will disappear. I think that the reason for this is that WM_ERASEBKGND will be sent to the child window (tab page) without a WM_PAINT after the key has been pressed. I don't think it is a good way just to ignore any WM_ERASEBKGND messages by implementing WindowProc(...), so does anybody know a better solution ?

    • RE: Strange behaviour on keypress (enter-/esc key)

      Posted by JOC_Consulting on 12/19/2009 02:05am

      I noticed the same problem of the Enter/Esc key causing the tab page dialog to disappear. According to the "Property Sheet as the View Window of a CFrameWnd" article at http://support.microsoft.com/kb/161886 , the reason is that the Enter and Esc keys, in MFC, are normally routed to OnOK and OnCancel, respectively. This article includes sample code that shows not only how to deal with the Enter and Esc keys, but also how to implement using Ctrl + Tab to go to the next tab page and Shift + Ctrl + Tab to go the previous tab page. My application has only 2 tabs so it hard to tell for sure, but this code seems to work properly.

    • RE:- Strange behaviour on keypress (enter-/esc key)

      Posted by LalitSRana on 04/22/2005 08:42am

      You can think of changing this behaviour by blocking these two keys.
      BOOL CDeltaLOCDlg::PreTranslateMessage(MSG* pMsg) 
      	// TODO: Add your specialized code here and/or call the base class
      		if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
      			pMsg->wParam=NULL ;
      	return CDialog::PreTranslateMessage(pMsg);

  • Select a tab programmatically

    Posted by Legacy on 12/08/2003 08:00am

    Originally posted by: Richard

    Firstly, many thanks to Ben Hill for showing me how to use the Tab Control. Like Alexis Giotis I also want to select a tab programmatically. Eventually I worked out how to do it by adding the another member function

    void SelectTab(int nextTab);

    to the CMyTabCtrl class declaration and the following definition

    void CMyTabCtrl::SelectTab(int nextTab)
    if(m_tabCurrent != GetCurFocus()){

    However, I can only get this to work when it is added after the line
    in CMyTabExampleDlg::OnInitDialog() which, although it can be used to change the initial tab, it is not what I want.

    If I use, say, m_tabMyTabCtrl.SelectTab(2); in another class (associated with a Check dialog with code in a TabCheck.cpp file) then I get an error message on compilation indicating that m_tabMyTabCtrl is not a class. I think that I have included all of the appropriate .h files in the .cpp file.

    This is all tied up with file scope. Please be kind to me as this is only my second C++ program! Although I am an experienced Fortran, Visual Basic programmer, C is new to me (and I am struggling).

  • Very cool but!

    Posted by Legacy on 11/20/2003 08:00am

    Originally posted by: Karim

    I have studied your code, and implemented it sucessfully in a dialog however...

    I am writing a control panel applet, and when used, none of the controls in the 'sub' dialogs seem to get focus or have the ability to respond when clicked.

    I personally belive this has somthing to do with implementing this code in a dll however, I am not sure. Any ideas?


    • Change parent?

      Posted by Sam Hobbs on 03/27/2004 04:21am

      I think the parent of the dialogs for the tabs is supposed to be the same parent as the tab control; that is not logical but Windows is not always logical. In this sample, the parent is the tab control.

  • Lose menu bar...

    Posted by Legacy on 10/02/2003 07:00am

    Originally posted by: Rico

    Hi All,

    When I use this tab control, it will make my menu bar at the button disappear.
    Is there any way to fix it?

    Many Thanks,

  • Problem with tab in the bottom and the "&"-sign

    Posted by Legacy on 08/21/2003 07:00am

    Originally posted by: Kenn

    Very great job with the tabcontrol, but one minor problem I can't fix.
    If you move the tabs to the bottom, everything is great, except when you add an "&"-sign anywhere in your text. The moment you press the specific tab, the text bumps up a bit. It looks a bit silly.

    Anyone know how to fix this ?

    Best regards, Kenn

  • Application Die

    Posted by Legacy on 08/17/2003 07:00am

    Originally posted by: chris

    I wonder anybody encountered this problem before.

    I had create a main Dialog with a button that will show a sub dialog when click.

    I create the tabControl in this sub Dialog. The funny thing is; I had no problem with one tab link to a child dialog. Problem occur when I try to add more tabs link to more child dialogs. The application die everytime I try to access the sub dialog. Worst, there is no error msg. I don't know where to trace my problem. Can somebody out there assist me?

    Thanks a million in advance.

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date