一、在对话框视图中加入CTabCtrl控件,资源ID:IDC_TAB,变量名:m_Tab
二、在OnInitDialog()中加入以下代码:
m_Tab.InsertItem(0,"窗口1");
m_Tab.InsertItem(1,"窗口2");
// 创建子窗口实例(事先创建好),将父窗口设为m_Tab
// CChileDlg1 m_dlgChile1;
// CChileDlg2 m_dlgChile2;
m_dlgChile1.Create(IDD_DIALOG_CHILD1,GetDlgItem(IDC_TAB));
m_dlgChile2.Create(IDD_DIALOG_CHILD2,GetDlgItem(IDC_TAB));
// 将子窗口显示在m_Tab范围内
CRect rs;
m_Tab.GetClientRect(rs);
rs.top+=20;
rs.bottom-=4;
rs.left+=4;
rs.right-=4;
m_dlgChile1.MoveWindow(rs);
m_dlgChile2.MoveWindow(rs);
// 默认显示第一个子窗口
m_Tab.SetCurSel(0);
m_dlgChile1.ShowWindow(TRUE);
三、响应m_Tab的TCN_SELCHANGE消息,实现切换页面功能
void CMyDlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
{
int nCurSel = m_Tab.GetCurSel();
switch(nCurSel)
{
case 0: // 显示子窗口1
m_dlgChile1.ShowWindow(TRUE);
m_dlgChile2.ShowWindow(FALSE);
break;
case 1: // 显示子窗口2
m_dlgChile1.ShowWindow(FALSE);
m_dlgChile2.ShowWindow(TRUE);
break;
}
*pResult = 0;
}
------------------------------------------------------------------------------------------------------
windows mobile的
PROPSHEETHEADER psh;
PROPSHEETPAGE psp[2];
int i = 0;
memset(&psh, 0, sizeof(PROPSHEETHEADER));
for(i = 0; i < 2; i++)
{
psp[i].dwSize = sizeof(PROPSHEETPAGE);
psp[i].dwFlags = PSP_DEFAULT | PSP_USETITLE;
psp[i].hInstance = g_hInst;
psp[i].lParam = (LPARAM)hWnd;
}
psp[0].pszTitle = TEXT("压缩文件");
psp[0].pszTemplate = MAKEINTRESOURCE(IDD_ZIPFILE);
psp[0].pfnDlgProc = (DLGPROC)ZipDlgProc;
psp[1].pszTitle = TEXT("解压文件");
psp[1].pszTemplate = MAKEINTRESOURCE(IDD_UNZIP);
psp[1].pfnDlgProc = (DLGPROC)UnzipDlgProc;
PROPSHEETPAGE psp[2];
int i = 0;
memset(&psh, 0, sizeof(PROPSHEETHEADER));
for(i = 0; i < 2; i++)
{
psp[i].dwSize = sizeof(PROPSHEETPAGE);
psp[i].dwFlags = PSP_DEFAULT | PSP_USETITLE;
psp[i].hInstance = g_hInst;
psp[i].lParam = (LPARAM)hWnd;
}
psp[0].pszTitle = TEXT("压缩文件");
psp[0].pszTemplate = MAKEINTRESOURCE(IDD_ZIPFILE);
psp[0].pfnDlgProc = (DLGPROC)ZipDlgProc;
psp[1].pszTitle = TEXT("解压文件");
psp[1].pszTemplate = MAKEINTRESOURCE(IDD_UNZIP);
psp[1].pfnDlgProc = (DLGPROC)UnzipDlgProc;
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_MAXIMIZE;
psh.hwndParent = hWnd;
psh.hInstance = g_hInst;
//psh.pszCaption = TEXT("Prop Sheet Title");
psh.nPages = 2;
psh.nStartPage = 0;
psh.ppsp = psp;
psh.pfnCallback = 0;
i = PropertySheet(&psh);
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_MAXIMIZE;
psh.hwndParent = hWnd;
psh.hInstance = g_hInst;
//psh.pszCaption = TEXT("Prop Sheet Title");
psh.nPages = 2;
psh.nStartPage = 0;
psh.ppsp = psp;
psh.pfnCallback = 0;
i = PropertySheet(&psh);