创建的子对话框必须设置style属性为child
CTabCtrl* ctbc = (CTabCtrl*)(GetDlgItem(IDC_TAB1));
ctbc->InsertItem(0, TEXT("chinese"));
ctbc->InsertItem(1, TEXT("english"));
m_dialog1.Create(IDD_DIALOG1, ctbc);
m_dialog2.Create(IDD_DIALOG2, ctbc);
CRect rect;
ctbc->GetClientRect(&rect);
rect.left += 1;
rect.right -= 1;
rect.top += 21;
rect.bottom -= 1;
m_dialog1.SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW);
m_dialog2.SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_HIDEWINDOW);
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &CMFCTrainDlg::OnTcnSelchangeTab1)
当选择不同的标签页时,标签控件不会自动切换,需要自己编写对话框切换代码
void CMFCTrainDlg::OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
CTabCtrl* ctbc = (CTabCtrl*)(GetDlgItem(IDC_TAB1));
CRect rect;
ctbc->GetClientRect(&rect);
rect.left += 1;
rect.right -= 1;
rect.top += 21;
rect.bottom -= 1;
switch (ctbc->GetCurSel())
{
case 0:
m_dialog1.SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW);
m_dialog2.SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_HIDEWINDOW);
break;
case 1:
m_dialog1.SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_HIDEWINDOW);
m_dialog2.SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW);
break;
default:
break;
}
}