选项卡控件中,5个标签页对应5个属性页对话框,与它们关联的类分别取名为CPage0、CPage1、CPage2、CPage3、CPage4。在CSpyXXDlg中建立私有成员变量m_page0、m_page1、m_page2、m_page3、m_page4。在其初始化过程中建立这5个属性页对话框:
m_page0.Create(IDD_OLE_PROPPAGE_LARGE,GetDlgItem(IDC_TAB1));
m_page1.Create(IDD_OLE_PROPPAGE_LARGE1,GetDlgItem(IDC_TAB1));
m_page2.Create(IDD_OLE_PROPPAGE_LARGE2,GetDlgItem(IDC_TAB1));
m_page3.Create(IDD_OLE_PROPPAGE_LARGE3,GetDlgItem(IDC_TAB1));
m_page4.Create(IDD_OLE_PROPPAGE_LARGE4,GetDlgItem(IDC_TAB1));
CRect rs;
m_tab.GetClientRect(rs);
rs.top+=20;
rs.bottom-=3;
rs.left+=3;
rs.right-=3;
m_page0.MoveWindow(rs);
m_page1.MoveWindow(rs);
m_page2.MoveWindow(rs);
m_page3.MoveWindow(rs);
m_page4.MoveWindow(rs);
m_page0.ShowWindow(SW_SHOW);
m_tab.SetCurSel(0);
然后在选项卡消息TCN_SELCHANGE响应函数中控制它们的显示:
void CSpyXXDlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int i=m_tab.GetCurSel();
switch(i)
{
case 0:
m_page0.ShowWindow(SW_SHOW);
m_page1.ShowWindow(SW_HIDE);
m_page2.ShowWindow(SW_HIDE);
m_page3.ShowWindow(SW_HIDE);
m_page4.ShowWindow(SW_HIDE);
break;
case 1:
m_page0.ShowWindow(SW_HIDE);
m_page1.ShowWindow(SW_SHOW);
m_page2.ShowWindow(SW_HIDE);
m_page3.ShowWindow(SW_HIDE);
m_page4.ShowWindow(SW_HIDE);
break;
case 2:
……
default:
;
}
*pResult = 0;
}