VC2005下tab控件的使用
1> 建立一个基于对话框的MFC智能设备应用程序。
2> 在主对话框中,添加一个Tab Control控件。
3> 为控件添加一个CtabCtrl类型的变量,如m_tabctrl。
4> 通过MFC类向导,添加几个新的对话框,
做为Tab Control的子对话框。
5> 修改新添加的对话框的属性,Border属性设置为None,
Sytle属性设置为Child。
6> 在主对话框的头文件中,声明新添加的几个对话框类的实例对象,
注意不要忘记添加那些对话框类的头文件。
如:
view plaincopy to clipboardprint?
CDialog1 m_Dlg1;
CDialog2 m_Dlg2;
CDialog3 m_Dlg3;
CDialog1 m_Dlg1;
CDialog2 m_Dlg2;
CDialog3 m_Dlg3;
7> 在主对话框的OnInitDialog()函数中添加如下代码:
CRect rect;
m_tabctrl.GetClientRect (&rect);
TCITEM item;
item.mask = TCIF_TEXT;
item.pszText =_T("General");
m_tabctrl.InsertItem (0,&item);
item.pszText =_T("Debug");
m_tabctrl.InsertItem (1,&item);
item.pszText =_T("C/C++");
m_tabctrl.InsertItem (2,&item);
item.pszText =_T("Link");
m_tabctrl.InsertItem (3,&item);
item.pszText =_T("Resources");
m_tabctrl.InsertItem (4,&item);
item.pszText =_T("MIDL");
m_tabctrl.InsertItem (5,&item);
m_Dlg1.Create (IDD_DIALOG1,&m_tabctrl);
m_Dlg2.Create (IDD_DIALOG2,&m_tabctrl);
m_Dlg3.Create (IDD_DIALOG3,&m_tabctrl);
m_Dlg4.Create (IDD_DIALOG4,&m_tabctrl);
m_Dlg5.Create (IDD_DIALOG5,&m_tabctrl);
m_Dlg6.Create (IDD_DIALOG6,&m_tabctrl);
m_Dlg1.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_SHOWWINDOW);
m_Dlg2.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg3.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg4.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg5.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg6.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
8> 在主对话框中为Tab控件添加TCN_SELCHANGE事件响应函数
CRect rect;
m_tabctrl.GetClientRect (&rect);
switch(m_tabctrl.GetCurSel())
{
case 0:
m_Dlg1.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_SHOWWINDOW);
m_Dlg2.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg3.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg4.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg5.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg6.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
break;
case 1:
m_Dlg1.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg2.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_SHOWWINDOW);
m_Dlg3.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg4.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg5.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg6.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
break;
case 2:
m_Dlg1.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg2.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg3.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_SHOWWINDOW);
m_Dlg4.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg5.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg6.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
break;
case 3:
m_Dlg1.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg2.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg3.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg4.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_SHOWWINDOW);
m_Dlg5.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg6.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
break;
case 4:
m_Dlg1.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg2.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg3.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg4.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg5.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_SHOWWINDOW);
m_Dlg6.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
break;
case 5:
m_Dlg1.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg2.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg3.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg4.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg5.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_HIDEWINDOW);
m_Dlg6.SetWindowPos (NULL,10,30,rect.right -20,rect.bottom -40,SWP_SHOWWINDOW);
break;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/joyzml/archive/2010/01/19/5213157.aspx