ComponentOne Sizer 8.0
Step 6: Add the pages to the Tab control

Now that we have created the main window and all the tab pages, we need to add the pages to the tab control. To do this, start by opening the main dialog's include file (C1TabTutDlg.h if you selected C1TabTut as the project name) and use the #include statement to bring in the page definitions (make sure you add the #include statements before the #if !defined statement added by the AppWizard).

Example Title
Copy Code
// TabOneTutDlg.h : header file

//

//{{AFX_INCLUDES()

#include "c1tab.h"

#include "c1elastic.h"

//}}AFX_INCLUDES

 

#include "TabPage1.h"

#include "TabPage2.h"

#include "TabPage3.h"

 

#if !defined(AFX_…__INCLUDED_)

#define AFX_…__INCLUDED_

…

Next, add a member variable for each page in the tab:

Example Title
Copy Code
// Implementation

protected:

       HICON m_hIcon;

 

       CTabPage1 m_Page1;

       CTabPage2 m_Page2;

       CTabPage3 m_Page3;

 

       // Generated message map functions

       //{{AFX_MSG(CTabOneTutDlg)

Now the main dialog class has three pages, which need to be created and added to the tab control. This is done in the OnInitDialog event handler (in the TabOneTutDlg.cpp file).

Example Title
Copy Code
BOOL CC1TabTutDlg::OnInitDialog()

{

       CDialog::OnInitDialog();

 

       …

 

       // TODO: Add extra initialization here

       // Create tab pages

       // (in reverse order to get the tab sequence right)

 

       m_Page3.Create(IDD_PAGE3);

       AdoptChildren(m_Page3.m_Elastic);

       m_pg3.SetParent(&m_TabOne);

       m_Page3.ShowWindow(SW_NORMAL);

 

       m_Page2.Create(IDD_PAGE2);

       AdoptChildren(m_Page3.m_Elastic);

       m_Page2.SetParent(&m_TabOne);

       m_Page2.ShowWindow(SW_NORMAL);

 

       m_Page1.Create(IDD_PAGE1);

       AdoptChildren(m_Page1.m_Elastic);

       m_Page1.SetParent(&m_TabOne);

       m_Page1.ShowWindow(SW_NORMAL);

      

       return TRUE;  // return TRUE unless you set the focus to a control

}

Code above repeats four steps to each page:

Example Title
Copy Code
e1.Create(IDD_PAGE1);

This statement creates the page. At this point, the page is not visible and it does not belong to the tab control yet.

Example Title
Copy Code
AdoptChildren(m_Page1.m_Elastic);

This statement tells the m_Elastic control on the page to "adopt" all controls that overlap it. Once the controls become children of the Elastic, they will be resized automatically.
The AdoptChildren function is provided as source code, in the SizerOneUtil.cpp file. You may either include this file in your project or simply copy the implementation into your project. (The function is listed in Appendix I below).

Example Title
Copy Code
m_Page1.SetParent(&m_TabOne);

This statement adds the page to the Tab. Notice that the pages are added in reverse order. If this bothers you, you can add them in any order you want and reposition them using the MoveWindow API).

Example Title
Copy Code
m_Page1.ShowWindow(SW_NORMAL);

This statement makes the page visible.

This is the end of the tutorial. It illustrates the main aspects and techniques involved in using the SizerOne controls in VC++.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback