声明一下,我不想公布我的邮箱,所以在这里贴出来,见谅。另外我对MFC也不精通,这些是我穷极无聊下所写的实验代码,你看看就好。
这里只列出关键代码,其他的我觉得很简单,你应该知道怎么做。
// tab_testView.h : interface of the CTab_testView class
//
/
#if !defined(AFX_TAB_TESTVIEW_H__8C5F47A2_B930_4A9F_BAF8_33F9922D0386__INCLUDED_)
#define AFX_TAB_TESTVIEW_H__8C5F47A2_B930_4A9F_BAF8_33F9922D0386__INCLUDED_
#include "Page2.h" // Added by ClassView
#include "Page1.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CTab_testView : public CFormView
{
protected: // create from serialization only
CTab_testView();
DECLARE_DYNCREATE(CTab_testView)
public:
//{{AFX_DATA(CTab_testView)
enum { IDD = IDD_TAB_TEST_FORM };
CTabCtrl m_tab;
//CDialog *pDialog[3];
//}}AFX_DATA
CDialog *pDialog[2];
// Attributes
public:
CTab_testDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTab_testView)
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual void OnInitialUpdate(); // called first time after construct
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
CPage2 m_page2;
CPage1 m_page1;
virtual ~CTab_testView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CTab_testView)
afx_msg void OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnButton1();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int m_CurSelTab;
};
#ifndef _DEBUG // debug version in tab_testView.cpp
inline CTab_testDoc* CTab_testView::GetDocument()
{ return (CTab_testDoc*)m_pDocument; }
#endif
/
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TAB_TESTVIEW_H__8C5F47A2_B930_4A9F_BAF8_33F9922D0386__INCLUDED_)
// tab_testView.cpp : implementation of the CTab_testView class
//
#include "stdafx.h"
#include "tab_test.h"
#include "tab_testDoc.h"
#include "tab_testView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CTab_testView
IMPLEMENT_DYNCREATE(CTab_testView, CFormView)
BEGIN_MESSAGE_MAP(CTab_testView, CFormView)
//{{AFX_MSG_MAP(CTab_testView)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/
// CTab_testView construction/destruction
CTab_testView::CTab_testView()
: CFormView(CTab_testView::IDD)
{
//{{AFX_DATA_INIT(CTab_testView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CTab_testView::~CTab_testView()
{
//for(int i=0; i<3; i++)
// delete pDialog[i];
}
void CTab_testView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTab_testView)
DDX_Control(pDX, IDC_TAB1, m_tab);
//}}AFX_DATA_MAP
}
BOOL CTab_testView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CTab_testView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
//为Tab Control增加两个页面
m_tab.InsertItem(0, _T("First"));
m_tab.InsertItem(1, _T("Second"));
//创建两个对话框
m_page1.m_str1 = "China on line";
m_page2.m_str2 = "hhhhhhh";
m_page1.Create(IDD_DIALOG1, &m_tab);
m_page2.Create(IDD_DIALOG2, &m_tab);
//设定在Tab内显示的范围
CRect rc;
m_tab.GetClientRect(rc);
rc.top += 20;
rc.bottom -= 8;
rc.left += 8;
rc.right -= 8;
m_page1.MoveWindow(&rc);
m_page2.MoveWindow(&rc);
//把对话框对象指针保存起来
pDialog[0] = &m_page1;
pDialog[1] = &m_page2;
//显示初始页面
pDialog[0]->ShowWindow(SW_SHOW);
pDialog[1]->ShowWindow(SW_HIDE);
//保存当前选择
m_CurSelTab = 0;
}
/
// CTab_testView printing
BOOL CTab_testView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTab_testView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTab_testView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CTab_testView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/
// CTab_testView diagnostics
#ifdef _DEBUG
void CTab_testView::AssertValid() const
{
CFormView::AssertValid();
}
void CTab_testView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CTab_testDoc* CTab_testView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTab_testDoc)));
return (CTab_testDoc*)m_pDocument;
}
#endif //_DEBUG
/
// CTab_testView message handlers
void CTab_testView::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
pDialog[m_CurSelTab]->ShowWindow(SW_HIDE);
m_CurSelTab = m_tab.GetCurSel();
pDialog[m_CurSelTab]->ShowWindow(SW_SHOW);
*pResult = 0;
}
void CTab_testView::OnButton1()
{
// TODO: Add your control notification handler code here
m_page1.UpdateData();
m_page2.UpdateData();
CString str1 = m_page1.m_str1;
CString str2 = m_page2.m_str2;
AfxMessageBox(str1);
AfxMessageBox(str2);
}