首页 > 代码库 > MFCTabCtrl

MFCTabCtrl

技术分享技术分享

//.h

CTabCtrl m_tabctrl;
#define MAX_DLG_PAGE 2
CDialog* m_pDialog[MAX_DLG_PAGE];
int m_iSelectedPage;
CPageProcess m_pageProcess;
CPageFile m_pageFile;

 

//.cpp

BOOL CDemoTabCtrlDlg::OnInitDialog()
{
//...

//插入页标题
m_tabctrl.InsertItem(0, _T("Process"));
m_tabctrl.InsertItem(1, _T("File"));

//页面绑定对话框,对话框绑定类,对话框Border(None),Style(Child)
m_pageProcess.Create(IDD_DIALOG1, &m_tabctrl);
m_pageFile.Create(IDD_DIALOG2, &m_tabctrl);

//设置页面的位置在m_tablist控件范围内
CRect rc;
m_tabctrl.GetClientRect(rc);
rc.top += 30;
rc.bottom -= 5;
rc.left += 5;
rc.right -= 5;

m_pDialog[0] = &m_pageProcess;
m_pDialog[1] = &m_pageFile;

m_pDialog[0]->MoveWindow(&rc);
m_pDialog[1]->MoveWindow(&rc);

//默认显示页
m_pDialog[0]->ShowWindow(TRUE);
m_pDialog[1]->ShowWindow(FALSE);

//...
}

 

//页面选择变化

void CDemoTabCtrlDlg::OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult)
{
m_pDialog[m_iSelectedPage]->ShowWindow(SW_HIDE);
m_iSelectedPage = m_tabctrl.GetCurSel();
if (m_pDialog[m_iSelectedPage])
{
m_pDialog[m_iSelectedPage]->ShowWindow(SW_SHOW);
}
*pResult = 0;
}

MFCTabCtrl