Introduction
Nowadays dialog based applications are becoming more and more popular. To make my future development for dialog based application easier I worked out this CTabDialog
, which operates like a Tab control, but gives you more chance to have your owner draw buttons and dialogs added. Hopefully CTabDialog
will make your development of dialog based application easier.
Using the code
To use the class
- Include the class to your application
#include
"TabDialog.h"
- Add the
CTabDialog
data member to your application: private:
CTabDialog* m_pTabDialog;
- In
OnInitDialog()
of your application, initialize the CTabDialog
m_pTabDialog = new CTabDialog(IDD_TABDLG, this);
if (m_pTabDialog->Create(IDD_TABDLG, this) == FALSE)
return FALSE;
m_pTabDialog->SetWindowPos(this, rect.left, rect.top, 0 , 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
Note: you need to create a dialog resource for the CTabDialog
control.
- You then need to add pages to the control
BOOL CTabDialogTestDlg::AddPagesToTabDialog()
{
m_pBtnOne = new CButton();
RECT rectOne;
rectOne.left = BTNONE_LOCATION.x;
rectOne.right = BTNONE_LOCATION.x+BUTTON_WIDTH;
rectOne.top = BTNONE_LOCATION.y;
rectOne.bottom = BTNONE_LOCATION.y+BUTTON_HEIGHT;
m_pBtnOne->Create("One", WS_CHILD | WS_VISIBLE | WS_TABSTOP, rectOne,
m_pTabDialog, BUTTON_ONE);
m_pPageOne = new CPageOneDlg(m_pTabDialog);
if (m_pPageOne->Create(IDD_PAGE_ONE, m_pTabDialog) == FALSE)
return FALSE;
m_pTabDialog->AddPage(m_pPageOne, m_pBtnOne);
m_pBtnTwo = new CButton();
RECT rectTwo;
rectTwo.left = BTNTWO_LOCATION.x;
rectTwo.right = BTNTWO_LOCATION.x+BUTTON_WIDTH;
rectTwo.top = BTNTWO_LOCATION.y;
rectTwo.bottom = BTNTWO_LOCATION.y+BUTTON_HEIGHT;
m_pBtnTwo->Create("Two", WS_CHILD | WS_VISIBLE | WS_TABSTOP, rectTwo,
m_pTabDialog, BUTTON_TWO);
m_pPageTwo = new CPageTwoDlg(m_pTabDialog);
if(m_pPageTwo->Create(IDD_PAGE_TWO, m_pTabDialog) == FALSE)
return FALSE;
m_pTabDialog->AddPage(m_pPageTwo, m_pBtnTwo);
m_pBtnThree = new CButton();
RECT rectThree;
rectThree.left = BTNTHREE_LOCATION.x;
rectThree.right = BTNTHREE_LOCATION.x+BUTTON_WIDTH;
rectThree.top = BTNTHREE_LOCATION.y;
rectThree.bottom = BTNTHREE_LOCATION.y+BUTTON_HEIGHT;
m_pBtnThree->Create("Three", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
rectThree, m_pTabDialog, BUTTON_THREE);
m_pPageThree = new CPageThreeDlg(m_pTabDialog);
if(m_pPageThree->Create(IDD_PAGE_THREE, m_pTabDialog) == FALSE)
return FALSE;
m_pTabDialog->AddPage(m_pPageThree, m_pBtnThree);
return TRUE;
}
- You then need to call
InitPagesShow()
member function of CTabDialog
to set the default showing of the control.
m_pTabDialog->InitPagesShow();