分类: C/C++
2008-03-04 10:54:06
//TabSampleDlg.h
/****************************************
* *
* Tab活页夹实例 *
* *
****************************************/
#pragma once
#include "afxcmn.h"
#include "TabSamplePage1Dlg.h"
#include "TabSamplePage2Dlg.h"
// CTabSampleDlg 对话框
class CTabSampleDlg : public CDialog
{
DECLARE_DYNAMIC(CTabSampleDlg)
public:
CTabSampleDlg(CWnd* pParent = NULL); // 标准构造函数
virtual ~CTabSampleDlg();
// 对话框数据
enum { IDD = IDD_DLG_TABSAMPLE };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
public:
virtual BOOL OnInitDialog() ;
public:
// Tab活页夹
CTabCtrl m_tab;
CTabSamplePage1Dlg m_page1 ;
CTabSamplePage2Dlg m_page2 ;
public:
afx_msg void OnTcnSelchangingTab(NMHDR *pNMHDR, LRESULT *pResult);
public:
afx_msg void OnTcnSelchangeTab(NMHDR *pNMHDR, LRESULT *pResult);
};
/////////////////////////////////
//TabSampleDlg.cpp
/////////////////////////////////
// TabSampleDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "MFC1.h"
#include "TabSampleDlg.h"
// CTabSampleDlg 对话框
IMPLEMENT_DYNAMIC(CTabSampleDlg, CDialog)
CTabSampleDlg::CTabSampleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTabSampleDlg::IDD, pParent)
{
}
CTabSampleDlg::~CTabSampleDlg()
{
}
void CTabSampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TAB, m_tab);
}
BEGIN_MESSAGE_MAP(CTabSampleDlg, CDialog)
ON_NOTIFY(TCN_SELCHANGING, IDC_TAB, &CTabSampleDlg::OnTcnSelchangingTab)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, &CTabSampleDlg::OnTcnSelchangeTab)
END_MESSAGE_MAP()
BOOL CTabSampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_tab.InsertItem(0,"属性一") ;
m_tab.InsertItem(1,"属性二") ;
m_page1.Create(IDD_DLG_TABSAMPLEPAGE1,GetDlgItem(IDC_TAB)) ;
m_page2.Create(IDD_DLG_TABSAMPLEPAGE2,GetDlgItem(IDC_TAB)) ;
CRect rs ;
m_tab.GetClientRect(&rs) ;
rs.left += 10 ;
rs.right -= 10 ;
rs.top += 25 ;
rs.bottom -= 10 ;
m_page1.MoveWindow(rs) ;
m_page2.MoveWindow(rs) ;
m_page1.ShowWindow(SW_SHOW) ;
m_tab.SetCurSel(0) ;
return true ;
}
// CTabSampleDlg 消息处理程序
void CTabSampleDlg::OnTcnSelchangingTab(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
}
void CTabSampleDlg::OnTcnSelchangeTab(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
int nCurSel = m_tab.GetCurSel() ;
switch(nCurSel){
case 0 :
{
m_page1.ShowWindow(SW_SHOW) ;
m_page2.ShowWindow(SW_HIDE) ;
}
break ;
case 1:
{
m_page1.ShowWindow(SW_HIDE) ;
m_page2.ShowWindow(SW_SHOW) ;
}
break ;
default:
{
}
break ;
}
}
/////////////////////////////////////////
//TabSamplePage1Dlg.h
/////////////////////////////////////////
#pragma once
#include "afxwin.h"
// CTabSamplePage1Dlg 对话框
class CTabSamplePage1Dlg : public CDialog
{
DECLARE_DYNAMIC(CTabSamplePage1Dlg)
public:
CTabSamplePage1Dlg(CWnd* pParent = NULL); // 标准构造函数
virtual ~CTabSamplePage1Dlg();
// 对话框数据
enum { IDD = IDD_DLG_TABSAMPLEPAGE1 };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
public:
CButton m_button1;
public:
afx_msg void OnBnClickedButton1();
};
/////////////////////////////////////
//TabSamplePage1.cpp
/////////////////////////////////////
// TabSamplePage1Dlg.cpp : 实现文件
//
#include "stdafx.h"
#include "MFC1.h"
#include "TabSamplePage1Dlg.h"
// CTabSamplePage1Dlg 对话框
IMPLEMENT_DYNAMIC(CTabSamplePage1Dlg, CDialog)
CTabSamplePage1Dlg::CTabSamplePage1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTabSamplePage1Dlg::IDD, pParent)
{
}
CTabSamplePage1Dlg::~CTabSamplePage1Dlg()
{
}
void CTabSamplePage1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BUTTON1, m_button1);
}
BEGIN_MESSAGE_MAP(CTabSamplePage1Dlg, CDialog)
ON_BN_CLICKED(IDC_BUTTON1, &CTabSamplePage1Dlg::OnBnClickedButton1)
END_MESSAGE_MAP()
// CTabSamplePage1Dlg 消息处理程序
void CTabSamplePage1Dlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
MessageBox("button1") ;
}
//////////////////////////////////////////////
//TabSamplePage2.h
//////////////////////////////////////////////
#pragma once
// CTabSamplePage2Dlg 对话框
class CTabSamplePage2Dlg : public CDialog
{
DECLARE_DYNAMIC(CTabSamplePage2Dlg)
public:
CTabSamplePage2Dlg(CWnd* pParent = NULL); // 标准构造函数
virtual ~CTabSamplePage2Dlg();
// 对话框数据
enum { IDD = IDD_DLG_TABSAMPLEPAGE2 };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
};
///////////////////////////////////////////
//TabSamplePage2.cpp
///////////////////////////////////////////
// TabSamplePage2Dlg.cpp : 实现文件
//
#include "stdafx.h"
#include "MFC1.h"
#include "TabSamplePage2Dlg.h"
// CTabSamplePage2Dlg 对话框
IMPLEMENT_DYNAMIC(CTabSamplePage2Dlg, CDialog)
CTabSamplePage2Dlg::CTabSamplePage2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTabSamplePage2Dlg::IDD, pParent)
{
}
CTabSamplePage2Dlg::~CTabSamplePage2Dlg()
{
}
void CTabSamplePage2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CTabSamplePage2Dlg, CDialog)
END_MESSAGE_MAP()
// CTabSamplePage2Dlg 消息处理程序