属性表单或属性页的制作
1:把一个资源关联一个类,
2:要创建一个属性表单类,用于创建属性表单
3:属性表单的模式
CPropSheet propSheet("维新属性表单程序");
propSheet.DoModal()
/创建的是一种向导的模式
CPropSheet propSheet("维新属性表单程序");
propSheet.SetWizardMode();
propSheet.DoModal();
4:设置上下页
BOOL CProp1::OnSetActive()
{
// TODO: Add your specialized code here and/or call the base class
((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_NEXT);
return CPropertyPage::OnSetActive();
}
5:当点击下一个按钮时调用OnWizardNext()这个函数,可以在此函数中保存接收该属性页上的变量的值,
LRESULT CProp1::OnWizardNext()
{
// TODO: Add your specialized code here and/or call the base class
UpdateData(); //此时相关联的变量保存选择项
if(m_occupation==-1)
{
MessageBox("请选择你的职业!");
return -1;
}
if(m_workAddr=="")
{
MessageBox("请选择你的工作地点!");
return -1;
}
return CPropertyPage::OnWizardNext();
}
点击完成按钮的响应函数OnWizardFinish()
BOOL CProp3::OnWizardFinish()
{
// TODO: Add your specialized code here and/or call the base class
int index;
index=((CComboBox*)GetDlgItem(IDC_COMBO2))->GetCurSel();
((CComboBox*)GetDlgItem(IDC_COMBO2))->GetLBText(index,m_strSalary); //选择保存在m_strSalary这变量中
return CPropertyPage::OnWizardFinish();
}
1:设置上一步,下一步等按钮
BOOL CProp1::OnSetActive() //重载基类的虚函数 且可知“属性页”的父窗口是“属性表单”
{
// TODO: Add your specialized code here and/or call the base class
((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_NEXT);
return CPropertyPage::OnSetActive();
}
2:单选、复选按钮实现选择
单选框一组只要一个变量
一般都是使用设置关联变量的方法,来保存你的选择。要初始化....
单选按钮是以group标记为一组的,第一个被选中,相关联的变量被赋值为0值,第二个赋值为1,依次递增........
重载这个虚函数OnWizardNext(),当下一步按钮被点击的时候,此时执行这个函数,且相关联的变量被赋予选择的值
LRESULT CProp1::OnWizardNext()
{
// TODO: Add your specialized code here and/or call the base class
UpdateData(); //必须要调用这个函数,相关联的变量被赋值的是DoDataExchange完成,但是只有updatedate()函数才能调用DoDataExchange函数
if(m_occupation==-1)
{
MessageBox("请选择你的职业!");
return -1; //返回0,自动跳转下一个页面,返回-1不会跳转下一个页面
}
if(m_workAddr=="")
{
MessageBox("请选择你的工作地点!");
return -1;
}
return CPropertyPage::OnWizardNext();
}
3:复选框,每个选项都要关联一个变量
4:组合框类,保存选择项使用的是,定义了一个成员变量,用来保存该选择
BOOL CProp3::OnWizardFinish()
{
// TODO: Add your specialized code here and/or call the base class
int index;
index=((CComboBox*)GetDlgItem(IDC_COMBO2))->GetCurSel();
((CComboBox*)GetDlgItem(IDC_COMBO2))->GetLBText(index,m_strSalary); //类中定义的成员变量
return CPropertyPage::OnWizardFinish();
}