包含控件頁的標籤式對話框,用戶可通過單擊鼠標在其間切換.
- 屬性表
- Tab控件
屬性表
屬性表的功能都合理地封裝在一對MFC類,CPropertySheet和CPropertyPage中.CPropertySheet代表屬性表自身,是從CWnd派生出來的.CPropertyPage代表屬性表的頁,是從CDialog派生出來的.
和對話框一樣,屬性表可以是模式和無模式的.CPropertySheet::DoModal創建模式屬性表,而CPropertySheet::Create創建無模式屬性表.
創建模式屬性表的步驟如下:
- 針對屬性表的每一頁創建一個對話框模板,定義頁的內容和特性.將對話框標題設置成您希望在屬性表頁上方標籤中顯現的標題.
- 針對屬性表的每一頁由CPropertyPage派生出一個類似對話框的類.其中包含通過DDX或DDV與頁面中控件相聯繫的公用數據成員.
- 由CPropertySheet派生出一個屬性表類.將該屬性表類和第2步中得到的屬性表頁類實例化.利用CPropertySheet::AddPage將各頁按期望中的顯示順序添加到屬性表中.
- 調用屬性表的DoModal函數將屬性表顯示在屏幕上.
簡單示例代碼
#pragma once
#include"resource.h"
// CFirstPage 對話框
class CFirstPage :public CPropertyPage
{
DECLARE_DYNAMIC(CFirstPage)
public:
CFirstPage();
virtual~CFirstPage();
// 對話框數據
enum{ IDD = IDD_PROPPAGE_FIRST };
protected:
virtualvoid DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
};
// FirstPage.cpp :實現文件
//
#include"stdafx.h"
#include"MFCExplore.h"
#include"FirstPage.h"
#include"afxdialogex.h"
// CFirstPage 對話框
IMPLEMENT_DYNAMIC(CFirstPage,CPropertyPage)
CFirstPage::CFirstPage()
:CPropertyPage(CFirstPage::IDD)
{
}
CFirstPage::~CFirstPage()
{
}
voidCFirstPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CFirstPage,CPropertyPage)
END_MESSAGE_MAP()
// CFirstPage 消息處理程序
CSecondPage類似於CFirstPage,略.
#pragma once
#include"afxdlgs.h"
#include"FirstPage.h"
#include"SecondPage.h"
classCMyPropertySheet :
publicCPropertySheet
{
public:
CMyPropertySheet(LPCTSTRpszCaption, CWnd* pParentWnd = NULL);
~CMyPropertySheet();
//第一頁屬性頁
CFirstPagem_firstPage;
//第二頁屬性頁
CSecondPagem_secondPage;
};
#include"stdafx.h"
#include"MyPropertySheet.h"
CMyPropertySheet::CMyPropertySheet(LPCTSTRpszCaption, CWnd* pParentWnd)
:CPropertySheet(pszCaption,pParentWnd, 0)
{
AddPage(&m_firstPage);
AddPage(&m_secondPage);
}
CMyPropertySheet::~CMyPropertySheet()
{
}
在CxxxApp::InitInstance()中創建模態屬性表.
CMyPropertySheetps(_T("Properties"));
m_pMainWnd =&ps;
INT_PTR nResponse =ps.DoModal();
參考自MFC Windows程序設計 8.4屬性表.