学用属性表

学用属性表
这里提供一种利用资源管理器创建属性表的方法:
第一步:利用资源管理器添加几个对话框作为属性页(这样可方便往属性页上添加控件并处理了)。
第二步:分别为作为属性页的对话框创建类,基类采用CPropertyPage。
第三步:利用类向导创建用户属性表类,基类采用CPropertySheet。
第四步:在刚创建的用户属性表类中添加需要属性页类数据成员,并在属性表类构造函数中调用CPropertySheet::AddPage函数将所需要的属性页一一添加到属性表中去。目前为止属性表类创建结束。
第五步: 在需要创建和显示属性表的地方构造用户属性表对象,并调用CPropertySheet::DoModal显示。
说明:
1)CPropertySheet
Objects of class CPropertySheet represent property sheets, otherwise known as tab dialog boxes. A property sheet consists of a CPropertySheet object and one or more CPropertyPage objects. A property sheet is displayed by the framework as a window with a set of tab indices, with which the user selects the current page, and an area for the currently selected page.

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

Exchanging data between a CPropertySheet object and some external object is similar to exchanging data with a CDialog object.

2)CPropertyPage
Objects of class CPropertyPage represent individual pages of a property sheet, otherwise known as a tab dialog box. As with standard dialog boxes, you derive a class from CPropertyPage for each page in your property sheet. 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.

3)Apply按钮的处理:
在所有的属性表类中,只要控件给属性页发送一个消息(如:点击或选择属性页上的控件,框架便调用该属性页OnCommand函数来响应这些控件所发出的通告消息,OnCommand函数是虚函数),在每个属性页中重载OnCommand函数设置SetModified(TRUE)可使Apply按钮有效。
当用户点击Apply按钮,框架自动调用OnApply函数,可以在重载它来完成一些重要的任务。
CWnd::OnCommand 
virtual BOOL OnCommand( WPARAM wParam, LPARAM lParam );
//The framework calls this member function when the user selects an item from a menu, when a child control sends a notification message, or when an accelerator keystroke is translated.

CPropertyPage::OnApply
virtual BOOL OnApply( );
//This member function is called by the framework when the user chooses the OK or the Apply Now button. When the framework calls this function, changes made on all property pages in the property sheet are accepted, the property sheet retains focus, and OnApply returns TRUE (the value 1). Before OnApply can be called by the framework, you must have called SetModified and set its parameter to TRUE. This will activate the Apply Now button as soon as the user makes a change on the property page.

Override this member function to specify what action your program takes when the user clicks the Apply Now button. When overriding, the function should return TRUE to accept changes and FALSE to prevent changes from taking effect.

The default implementation of OnApply calls OnOK.

于属性对话框可以使用下面的一些成员函数:

CPropertyPage* CPropertySheet::GetActivePage( )得到当前活动页的指针。
BOOL CPropertySheet::SetActivePage( int nPage )用于设置当前活动页。
int CPropertySheet::GetPageCount()用于得到当前页总数。
void CPropertySheet::RemovePage( int nPage )用于删除一页。
而对于属性页来将主要通过重载一些函数来达到控制的目的:
void CPropertyPage::OnOK() 在属性对话框上按下“确定”按钮后被调用
void CPropertyPage::OnCancel() 在属性对话框上按下“取消”按钮后被调用
void CPropertyPage::OnApply() 在属性对话框上按下“应用”按钮后被调用
void CPropertyPage::SetModified( BOOL bChanged = TRUE ) 设置当前页面上的数据被修改标记,这个调用可以使“应用”按钮为允许状态。
此外利用属性对话框你可以生成向导对话框,向导对话框同样拥有多个属性页,但同时只有一页被显示,而且对话框上显示的按钮为“上一步”,“下一步”/“完成”,向导对话框会按照你添加页面的顺序依次显示所有的页。在显示属性对话框前你需要调用void CPropertySheet::SetWizardMode()。使用向导对话框时需要对属性页的BOOL CPropertyPage::OnSetActive( )进行重载,并在其中调用void CPropertySheet::SetWizardButtons( DWORD dwFlags )来设置向导对话框上显示的按钮。dwFlags的取值可为以下值的“或”操作:
PSWIZB_BACK 显示“上一步”按钮
PSWIZB_NEXT 显示“下一步”按钮
PSWIZB_FINISH 显示“完成”按钮
PSWIZB_DISABLEDFINISH 显示禁止的“完成”按钮
void CPropertySheet::SetWizardButtons( DWORD dwFlags )也可以在其他地方调用,比如说在显示最后一页时先显示禁止的“完成”按钮,在完成某些操作后再显示允许的“完成”按钮。

在使用向导对话框时可以通过重载一些函数来达到控制的目的:

void CPropertyPage::OnWizardBack() 按下了“上一步”按钮。返回0表示有系统决定需要显示的页面,-1表示禁止页面转换,如果希望显示一个特定的页面需要返回该页面的ID号。
void CPropertyPage::OnOnWizardNext() 按下了“下一步”按钮。返回值含义与void CPropertyPage::OnWizardBack()相同。
void CPropertyPage::OnWizardFinish() 按下了“完成”按钮。返回FALSE表示不允许继续,否则返回TRUE向导对话框将被结束。
在向导对话框的DoModal()返回值为ID_WIZFINISH或IDCANCEL。下面的代码演示了如何创建并使用向导对话框:
//创建有模式向导对话框
void CMy56_s1Dlg::OnWiz()
{
 CSheet sheet;
 sheet.SetWizardMode();
 int iRet=sheet.DoModal();//返回ID_WIZFINISH或IDCANCEL
}
//重载BOOL CPropertyPage::OnSetActive( )来控制显示的按钮
BOOL CPage1::OnSetActive()
{
 ((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK|PSWIZB_NEXT);
 return CPropertyPage::OnSetActive();
}
BOOL CPage2::OnSetActive()
{
 ((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK|PSWIZB_FINISH);
 return CPropertyPage::OnSetActive();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值