add a property table dlg is simple.add a dig with var:CTabCtr's son:CTabSheet m_sheet,and 3 dialog son as pages;then ok.
1:CTableSheet:
#define MAXPAGE 100
/////////////////////////////////////////////////////////////////////////////
// CTabSheet window
class CTabSheet : public CTabCtrl
{
// Construction
public:
CTabSheet();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTabSheet)
//}}AFX_VIRTUAL
// Implementation
public:
int GetCurSel();
int SetCurSel(int nItem);
void Show();
void SetRect();
BOOL AddPage(LPCTSTR title, CDialog *pDialog, UINT ID);
virtual ~CTabSheet();
// Generated message map functions
protected:
LPCTSTR m_Title[MAXPAGE];
UINT m_IDD[MAXPAGE];
CDialog* m_pPages[MAXPAGE];
int m_nNumOfPages;
int m_nCurrentPage;
//{{AFX_MSG(CTabSheet)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
implement:
/////////////////////////////////////////////////////////////////////////////
// CTabSheet
CTabSheet::CTabSheet()
{
m_nNumOfPages = 0;
m_nCurrentPage = 0;
}
CTabSheet::~CTabSheet()
{
}
BEGIN_MESSAGE_MAP(CTabSheet, CTabCtrl)
//{{AFX_MSG_MAP(CTabSheet)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTabSheet message handlers
BOOL CTabSheet::AddPage(LPCTSTR title, CDialog *pDialog,UINT ID)
{
if( MAXPAGE == m_nNumOfPages )
return FALSE;
m_nNumOfPages++;
m_pPages[m_nNumOfPages-1] = pDialog;
m_IDD[m_nNumOfPages-1] = ID;
m_Title[m_nNumOfPages-1] = title;
return TRUE;
}
void CTabSheet::SetRect()
{
CRect tabRect, itemRect;
int nX, nY, nXc, nYc;
GetClientRect(&tabRect);
GetItemRect(0, &itemRect);
nX=itemRect.left;
nY=itemRect.bottom+1;
nXc=tabRect.right-itemRect.left-2;
nYc=tabRect.bottom-nY-2;
m_pPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
for( int nCount=1; nCount < m_nNumOfPages; nCount++ )
m_pPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
}
void CTabSheet::Show()
{
for( int i=0; i < m_nNumOfPages; i++ )
{
m_pPages[i]->Create( m_IDD[i], this );
InsertItem( i, m_Title[i] );
}
m_pPages[0]->ShowWindow(SW_SHOW);
for( i=1; i < m_nNumOfPages; i++)
m_pPages[i]->ShowWindow(SW_HIDE);
SetRect();
}
void CTabSheet::OnLButtonDown(UINT nFlags, CPoint point)
{
CTabCtrl::OnLButtonDown(nFlags, point);
if(m_nCurrentPage != GetCurFocus())
{
m_pPages[m_nCurrentPage]->ShowWindow(SW_HIDE);
m_nCurrentPage=GetCurFocus();
m_pPages[m_nCurrentPage]->ShowWindow(SW_SHOW);
// m_pPages[m_nCurrentPage]->SetFocus();
}
}
int CTabSheet::SetCurSel(int nItem)
{
if( nItem < 0 || nItem >= m_nNumOfPages)
return -1;
int ret = m_nCurrentPage;
if(m_nCurrentPage != nItem )
{
m_pPages[m_nCurrentPage]->ShowWindow(SW_HIDE);
m_nCurrentPage = nItem;
m_pPages[m_nCurrentPage]->ShowWindow(SW_SHOW);
// m_pPages[m_nCurrentPage]->SetFocus();
CTabCtrl::SetCurSel(nItem);
}
return ret;
}
int CTabSheet::GetCurSel()
{
return CTabCtrl::GetCurSel();
}
2: how to use it in dialog:
#include "dia1.h"
#include "dia2.h"
#include "dia3.h"
#include "Sheet.h"
/////////////////////////////////////////////////////////////////////////////
// SheetDlg dialog
class SheetDlg : public CDialog
{
// Construction
public:
dia1 d1;
dia2 d2;
dia3 d3;
SheetDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(SheetDlg)
enum { IDD = IDD_SheetDlg };
CTabSheet m_sheet;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(SheetDlg)
public:
virtual BOOL Create(CWnd* pParentWnd, UINT nID) ;
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(SheetDlg)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_SHEETDLG_H__04238402_BC94_4156_8B15_30A5AD32648B__INCLUDED_)
imp:
#include "stdafx.h"
#include "testProper1.h"
#include "SheetDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// SheetDlg dialog
SheetDlg::SheetDlg(CWnd* pParent /*=NULL*/)
: CDialog(SheetDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(SheetDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void SheetDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(SheetDlg)
DDX_Control(pDX, IDC_TAB1, m_sheet);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(SheetDlg, CDialog)
//{{AFX_MSG_MAP(SheetDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// SheetDlg message handlers
LRESULT SheetDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::DefWindowProc(message, wParam, lParam);
}
BOOL SheetDlg::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
return CDialog::Create(IDD, pParentWnd);
}
BOOL SheetDlg::Create(CWnd* pParentWnd, UINT nID)
{
return CDialog::Create(IDD, pParentWnd);
}
BOOL SheetDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//
// TODO: Add extra initialization here
m_sheet.AddPage("tab1", &d1, IDD_DIA1);
m_sheet.AddPage("tab2", &d2, IDD_DIA2);
m_sheet.AddPage("tab3", &d3, IDD_DIA3);
m_sheet.Show();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
3:pages only page 3 as an exmaple
(*********attention:must style set child and none frame and boder and title,other wise not seem ok)
/////////////////////////////////////////////////////////////////////////////
// dia3 dialog
class dia3 : public CDialog
{
// Construction
public:
dia3(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(dia3)
enum { IDD = IDD_DIA3 };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(dia3)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(dia3)
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DIA3_H__2E6FF0FB_D730_4D53_9525_68A9352A1E32__INCLUDED_)
imp:
/////////////////////////////////////////////////////////////////////////////
// dia3 dialog
dia3::dia3(CWnd* pParent /*=NULL*/)
: CDialog(dia3::IDD, pParent)
{
//{{AFX_DATA_INIT(dia3)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void dia3::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(dia3)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(dia3, CDialog)
//{{AFX_MSG_MAP(dia3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// dia3 message handlers
void dia3::OnOK()
{
CEdit *ed=(CEdit*)GetDlgItem(IDC_E1);
CString t;
ed->GetWindowText(t);
AfxMessageBox(t);
// CDialog::OnOK();
}