标签控件相当于一个页面容器,可以容纳多个对话框;
CTabCtrl类主要成员函数
Int GetCueSel()const ; 获取标签控件中当前选择标签索引
BOOL GetItem(int nItem,TCITEM* pTabCtrItem)const; //获取标签某个标签的信息
BOOL SetItem(int nItem,TCITEM* pTabCteltem) const;//设置某标签的所有或部分属性
每个对话框的边框风格改为无边框,child子窗口
类成员变量及函数
// CCTabControlDlg 对话框,初始化
class CCTabControlDlg : public CDialogEx
{
……
public:
CTabCtrl m_CTabCtrl;
CNomalDlg m_CNomalDlg; //常规对话框
CBeginDlg m_CBeginDlg; //启动对话框
afx_msg void OnTcnSelchangeTabSystemconfig(NMHDR *pNMHDR, LRESULT *pResult); //控件响应函数
};
BOOL CCTabControlDlg::OnInitDialog()
{
CDialogEx::OnInitDialog()
………..
// TODO: 在此添加额外的初始化代码
//初始化标签控件
TC_ITEM tcItem; //标签控件
tcItem.mask = TCIF_TEXT;
tcItem.pszText = L"常规";
//添加标签页
m_CTabCtrl.InsertItem(0, &tcItem);
tcItem.pszText = L"引导";
m_CTabCtrl.InsertItem(1, &tcItem);
tcItem.pszText = L"服务";
m_CTabCtrl.InsertItem(2, &tcItem);
tcItem.pszText = L"启动";
m_CTabCtrl.InsertItem(3, &tcItem);
tcItem.pszText = L"工具";
m_CTabCtrl.InsertItem(4, &tcItem);
//设置默认选择项
m_CTabCtrl.SetCurSel(3);
//初始化
CRect tabRect;
m_CBeginDlg.Create(IDD_DIALOG_BEGIN, &m_CTabCtrl);
m_CNomalDlg.Create(IDD_DIALOG_NOMAL, &m_CTabCtrl);
m_CTabCtrl.GetClientRect(&tabRect);
//调整tableRect大小,适合放置标签
tabRect.left += 1;
tabRect.right -= 1;
tabRect.top += 25;
tabRect.bottom -= 1;
//根据调整好的tabRect放到子对话框中
m_CBeginDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(),tabRect.Height(),SWP_SHOWWINDOW);
m_CNomalDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW);//隐藏窗口
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
CTabControl控件消息函数
void CCTabControlDlg::OnTcnSelchangeTabSystemconfig(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
int nSelectCur = 0;
CRect tabRect;
m_CTabCtrl.GetClientRect(&tabRect);
//调整tableRect大小,适合放置标签
tabRect.left += 1;
tabRect.right -= 1;
tabRect.top += 25;
tabRect.bottom -= 1;
nSelectCur = m_CTabCtrl.GetCurSel();
switch (nSelectCur)
{
case 0:
{
m_CBeginDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW );
m_CNomalDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW);
}
break;
case 1: break;
case 2: break;
case 3:
{
m_CBeginDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_SHOWWINDOW);
m_CNomalDlg.SetWindowPos(NULL, tabRect.left, tabRect.top, tabRect.Width(), tabRect.Height(), SWP_HIDEWINDOW);
}
break;
case 4: break;
}
*pResult = 0;
}
启动对话框中添加静态控件用来打开任务管理器
void CBeginDlg::OnStnClickedStaticOptask()
{
// TODO: 在此添加控件通知处理程序代码
ShellExecute(this->m_hWnd, L"open", L"taskmgr.exe", L"", L"",SW_SHOW);
}