Introduction
I take this opportunity to thank all my friends who commented and gave ideas about my previous tab control. It made me build this useful and easy tab control for all of you.
About this new tab control
If you are using this particular tab control, you have to do the following steps:
- Drag and drop the VC++ tab control on to your dialog.
- Add CIbTabCtrl.c and CIbTabCtrl.h to your solution.
- Derive the tab control variable from
CIbTabCtrl
.
You are free to design your tab pages using property pages. Add property pages to your application using the Add Resource option. Then create a property page associated class using CPropertyPage
. You can add any number of property pages to your application. To make it visually suitable for a tab control, you can set the following property values:
- Set Border property to None
- Set Control property to True (this is very important; if it is false, the tab key function will not have any effect).
- Set the Disable property to False
Once you create your property pages, you have to link those pages with your tab control.
How to link pages with the tab control
- Create property page objects as members of the dialog where your control is (if property page classes are
CPPone
and CPPTwo
):
CPPOne m_oPPOne;
CPPTwo m_oPPTwo;
- On the OnInitDialog member function:
m_oPPOne.Create(IDD_PP_ONE);
m_oPPTwo.Create(IDD_PP_TWO);
m_ctrlTabV.addNewPage("My Page 1",&m_oPPOne);
m_ctrlTabV.addNewPage("My Page 2",&m_oPPTwo);
m_ctrlTabV.setDefaultPage(0);
That's it! This is all you have to do to use this control in your solution.
For those interested in the CIbTabCtrl class
This class is derived from the MFC CTabCtrl
class. I have added three functions:
AddNewPage(CString strPage, CWnd * pPage)
(public)This will keep track of all the pages added. Here I am using the CArray
member variable to keep those pages.
InsertItem(this->GetItemCount(),strPage);
pPage->ShowWindow(SW_HIDE);
m_oPages.Add(pPage);
setPage(CWnd* pWnd)
(private member function)This will display and draw a page according to the size of the tab control.
CIbTabCtrl::setPage(CWnd* pWnd)
{
CWnd * pPage;
pPage = m_oPages.GetAt(m_iPrevPage);
pPage->ShowWindow(SW_HIDE);
CRect oRect,oWRect,oPWRect,oIRect;
GetItemRect(0,oIRect);
GetClientRect(oRect);
GetWindowRect(oWRect);
GetParent()->GetWindowRect(oPWRect);
pWnd->SetWindowPos(this,oWRect.left-oPWRect.left,oWRect.top-oPWRect.top,
oRect.Width()- 5,oRect.Height()-oIRect.Height() - void 6, SWP_SHOWWINDOW);
}
setDefaultPage(int iIndex)
(public)Sets the default page.
- removePage(int iIndex) (public)
This will remove the tab page from the tab control.
Hope this description is enough for you to use this control. You are free to ask any question on this article. I am sure you will enjoy this control very much.