VC:CTabCtrl

(插入项、获取Tab控件的句柄、以Tab控件位父窗口(GetDlgItem(TabID)获取句柄)和对话框ID创建子对话框,获取客户区,将新建的对话框移入客户区,获取当前选择的对话框序号、显示对话框)

特别注意:TabCtrl控件,要占据整个对话框,否则太小显示不出来。

1、类向导为两个对话框添加俩类:CDialog1和CDialog2;

2、C*Dlg主对话框类中,引入两个对话框的头文件,并添加俩个对象:dlg1,dlg2;

3、主对话框初始化:

       m_Tab.InsertItem(0,"对话框1");

              m_Tab.InsertItem(1,"对话框2");

              dlg1.Create(IDD_DIALOG1,GetDlgItem(IDC_TAB));

              dlg2.Create(IDD_DIALOG2,GetDlgItem(IDC_TAB));

              CRect rect;

              m_Tab.GetClientRect(rect);

              rect.top+=30;

              rect.bottom-=5;

              rect.left+=5;

              rect.right-=5;

              dlg1.MoveWindow(rect);

              dlg2.MoveWindow(rect);

              dlg1.ShowWindow(true);

              dlg2.ShowWindow(false);

              m_Tab.SetCurSel(0);

4、类向导添加TCN_SELCHANGE、或TCN_SELCHANGING消息映射;

void CTabCtrlDlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)

{

       // TODO: Add your control notification handler code here

       int n=m_Tab.GetCurSel();

       switch(n)

       {

       case 0:

              dlg1.ShowWindow(true);

              dlg2.ShowWindow(false);

              break;

       case 1:

              dlg1.ShowWindow(false);

              dlg2.ShowWindow(true);

              break;

       }

       *pResult = 0;

}

你可能感兴趣的:(tab)