现在的位置: 首页 > 综合 > 正文

VC++ MFC属性页使用说明(孙鑫视频教程总结)(3)

2013年09月05日 ⁄ 综合 ⁄ 共 2254字 ⁄ 字号 评论关闭

14、 设置第一个属性页“工作地点”项的数据和页面数据校验。

a)         完善“工作地点项”的数据:首先为“CProp1”这个类添加一个消息响应函数OnInitDialog(),保证在初始化属性页的时候进行数据的初始化,然后

          ((CListBox*)this->GetDlgItem(IDC_LIST1))->AddString("上海");

          ((CListBox*)this->GetDlgItem(IDC_LIST1))->AddString("北京");

         ((CListBox*)this->GetDlgItem(IDC_LIST1))->AddString("成都");

这样完成数据的初始化

b)         OnWizardNext()函数中判断时候选择“工作地点”中的值

If(m_workAddr==””)

{

         MessageBox(“请选择工作地点!”);

         return -1;

}

c)         完成之后1415步的代码:

LRESULT CProp1::OnWizardNext()

{

         // TODO: Add your specialized code here and/or call the base class

         this->UpdateData();

         if(m_occupation==-1)

         {

                   MessageBox("请选择职位!");

                   return -1;

         }

         if(m_workAddr=="")

         {

                   MessageBox("请选择工作地点!");

                   return -1;

         }

         return CPropertyPage::OnWizardNext();

}

15、 设置第二个属性页的数据和数据校验

a)         首先关联变量:将各项均关联成BOOL型的m_basketballm_footballm_swim m_volleyball

b)         OnWizardNext()函数中先更新数据,再判断,若是四个成员变量之中有一个为真,则可以进行“下一步”,否则提示,并保持当前属性页

c)         代码

LRESULT CProp2::OnWizardNext()

{

          // TODO: Add your specialized code here and/or call the base class

          this->UpdateData();

          if(m_basketball || m_football || m_swim || m_volleyball)

          {

                   return CPropertyPage::OnWizardNext();

          }

          else

          {

                   MessageBox("请选择爱好!");

                   return -1;

          }

}

16、 设置第三个属性页的数据和数据校验

a)         ComboBox关联CString类型变量m_salary

b)         初始化数据:

BOOL CProp3::OnInitDialog()

{

          CPropertyPage::OnInitDialog();

         

          // TODO: Add extra initialization here

          ((CComboBox*)this->GetDlgItem(IDC_COMBO1))->AddString("1000元以下");

          ((CComboBox*)this->GetDlgItem(IDC_COMBO1))->AddString("1000-3000");

          ((CComboBox*)this->GetDlgItem(IDC_COMBO1))->AddString("3000元以上");

          return TRUE; // return TRUE unless you set the focus to a control

                        // EXCEPTION: OCX Property Pages should return FALSE

}

c)         校验数据

BOOL CProp3::OnWizardFinish()

{

          // TODO: Add your specialized code here and/or call the base class

          this->UpdateData();

          if(m_salary=="")

          {

                   MessageBox("请选择薪资水平!");

                   return FALSE;

          }

          return CPropertyPage::OnWizardFinish();

}

至此我们完成了全部属性页的数据初始化和校验工作

抱歉!评论已关闭.