属性页与属性表单

 

必备知识:

属性页相应的类CPropertyPage.其继承关系为C0bject------CCmdTarget----CWnd----CDialog----CPropertyPage.

The CPropertyPage class encapsulates a single page of a Windows property sheet.

属性页类封装了Windows操作系统的属性表单的一页.

属性类的使用方法:

To use CPropertyPage-derived objects, first create a CPropertySheet object, and then create an object for each page that goes in the property sheet. Call CPropertySheet::AddPage for each page in the sheet, and then display the property sheet by calling CPropertySheet::DoModal for a modal property sheet, or CPropertySheet::Create for a modeless property sheet.

 

 

 

属性表单相应的类为CPropertySheet.其继承关系为C0bject-----CCmdTarget----CWnd-----CPropertySheet

The CPropertySheet class encapsulates a Windows property sheet, otherwise known as a tabbed dialog box. A property sheet consists of a CPropertySheet object and one or more CPropertyPage objects

属性表单类封装了Windows操作系统的属性表单.属性表单也叫做标签对话框.一个属性表单(窗口)是由一个属性表单类对象和一个或多个的属性页类对象组成.

Even though CPropertySheet is not derived from CDialog, managing a CPropertySheet object is similar to managing a CDialog object.

即使属性表单类不是从对话框类继承.但操作一个属性表单类对象类似与操作一个对话框对象.

2.每一种资源都对应着相应的MFC类.

3.若你的应用程序没有相应的类对应着资源.则从相应的类派生出一个类.

 

下面简略的操作过程.

1.从对话框资源插入属性页资源.

2.利用CLASSWIZARD创建相应的类CProp1,CProp2,CProp3.

CProp1的头文件

#if !defined(AFX_PROP1_H__6DDC2336_EB22_41FB_A466_AA970E45EB5C__INCLUDED_)
#define AFX_PROP1_H__6DDC2336_EB22_41FB_A466_AA970E45EB5C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Prop1.h : header file
//

/
// CProp1 dialog

class CProp1 : public CPropertyPage
{
 DECLARE_DYNCREATE(CProp1)//支持动态创建

// Construction
public:
 CProp1();
 ~CProp1();

// Dialog Data
 //{{AFX_DATA(CProp1)
 enum { IDD = IDD_PROP1 };
  // NOTE - ClassWizard will add data members here.
  //    DO NOT EDIT what you see in these blocks of generated code !
 //}}AFX_DATA


// Overrides
 // ClassWizard generate virtual function overrides
 //{{AFX_VIRTUAL(CProp1)
 protected:
 virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 //}}AFX_VIRTUAL

// Implementation
protected:
 // Generated message map functions
 //{{AFX_MSG(CProp1)
  // NOTE: the ClassWizard will add member functions here
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()

};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_PROP1_H__6DDC2336_EB22_41FB_A466_AA970E45EB5C__INCLUDED_)
CProp1的.cpp文件

// Prop1.cpp : implementation file
//

#include "stdafx.h"
#include "CProp.h"
#include "Prop1.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
// CProp1 property page

IMPLEMENT_DYNCREATE(CProp1, CPropertyPage)

CProp1::CProp1() : CPropertyPage(CProp1::IDD)
{
 //{{AFX_DATA_INIT(CProp1)
  // NOTE: the ClassWizard will add member initialization here
 //}}AFX_DATA_INIT
}

CProp1::~CProp1()
{
}

void CProp1::DoDataExchange(CDataExchange* pDX)
{
 CPropertyPage::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CProp1)
  // NOTE: the ClassWizard will add DDX and DDV calls here
 //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CProp1, CPropertyPage)
 //{{AFX_MSG_MAP(CProp1)
  // NOTE: the ClassWizard will add message map macros here
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CProp1 message handlers
可以发现,和对话框类很相似.

3.插入一个新类CPropSheet,从CPropertySheet继承.

CPropSheet.h

 

#if !defined(AFX_PROPSHEET_H__A978D78B_971A_4316_B7E1_5C25A3EBCEE2__INCLUDED_)
#define AFX_PROPSHEET_H__A978D78B_971A_4316_B7E1_5C25A3EBCEE2__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// PropSheet.h : header file
//

/
// CPropSheet

class CPropSheet : public CPropertySheet
{
 DECLARE_DYNAMIC(CPropSheet)

// Construction
public:
 CPropSheet(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
 CPropSheet(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);

// Attributes
public:

// Operations
public:

// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CPropSheet)
 //}}AFX_VIRTUAL

// Implementation
public:
 virtual ~CPropSheet();

 // Generated message map functions
protected:
 //{{AFX_MSG(CPropSheet)
  // NOTE - the ClassWizard will add and remove member functions here.
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

/

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_PROPSHEET_H__A978D78B_971A_4316_B7E1_5C25A3EBCEE2__INCLUDED_)

CPropSheet.cpp

// PropSheet.cpp : implementation file
//

#include "stdafx.h"
#include "CProp.h"
#include "PropSheet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
// CPropSheet

IMPLEMENT_DYNAMIC(CPropSheet, CPropertySheet)

CPropSheet::CPropSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
 :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
}

CPropSheet::CPropSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
 :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
}

CPropSheet::~CPropSheet()
{
}


BEGIN_MESSAGE_MAP(CPropSheet, CPropertySheet)
 //{{AFX_MSG_MAP(CPropSheet)
  // NOTE - the ClassWizard will add and remove mapping macros here.
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CPropSheet message handlers

发现比对话框类少了 DoDataExchange()函数.

 

在CPropSheet类头文件添加相应的成员变量.

#include "Prop1.h"
#include "Prop2.h"
#include "Prop3.h"

 

 

CProp1  m_prop1;

CProp2   m_prop2;

CProp3  m_prop3;

在CPropSheet类的构造函数调用AddPage().

CPropSheet::CPropSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
 :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
 AddPage(&m_prop1);
 AddPage(&m_prop2);
 AddPage(&m_prop3);
}

CPropSheet::CPropSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
 :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
 AddPage(&m_prop1);
 AddPage(&m_prop2);
 AddPage(&m_prop3);
}

 

4.添加一个子菜单----属性表单.添加WM_COMMAND消息的响应函数.

void CCPropView::OnProp()
{
 // TODO: Add your command handler code here
 CPropSheet psSheet1("属性表单");
 psSheet1.DoModal();
}

//注意在文件开头要添加#include "PropSheet.h"

 

 

好了实现了功能.

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值