1. 程序启动时初始化Tab控件
m_tab.InsertItem(0, L"第一页");
m_tab.InsertItem(1, L"第二页");
m_tab.InsertItem(2, L"第三页");
// 关联对话框,并且将IDC_TABTEST控件设为父窗口
m_para1.Create(IDD_PARA1, GetDlgItem(IDC_TABTEST));
m_para2.Create(IDD_PARA2, GetDlgItem(IDC_TABTEST));
m_result.Create(IDD_RESULT, GetDlgItem(IDC_TABTEST));
// 获得IDC_TABTEST客户区大小
CRect rs; m_tab.GetClientRect(&rs);
// 调整子对话框在父窗口中的位置
rs.top += 1;
rs.bottom -= 60;
rs.left += 1;
rs.right -= 2;
// 设置子对话框尺寸并移动到指定位置
m_para1.MoveWindow(&rs);
m_para2.MoveWindow(&rs);
m_result.MoveWindow(&rs);
// 分别设置隐藏和显示
m_para1.ShowWindow(TRUE);
m_para2.ShowWindow(FALSE);
m_result.ShowWindow(FALSE);
//设置默认的选项卡
m_tab.SetCurSel(0);
2. 添加Tab控件标签更改时的事件
void CTabCtl_DemoDlg::OnTcnSelchangeTabtest(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
int CurSel = m_tab.GetCurSel();
switch(CurSel)
{
case 0:
m_para1.ShowWindow(TRUE);
m_para2.ShowWindow(FALSE);
m_result.ShowWindow(FALSE);
break;
case 1:
m_para1.ShowWindow(FALSE);
m_para2.ShowWindow(TRUE);
m_result.ShowWindow(FALSE);
break;
case 2:
m_para1.ShowWindow(FALSE);
m_para2.ShowWindow(FALSE);
m_result.ShowWindow(TRUE);
break;
default:
break;
}
*pResult = 0;
}
3. 对于Tab页内的内容分别创建无边框的对话框进行设计使用,使用方法与多对话框方法相同