MFC对话框(二)
来源:互联网 发布:时代软件 编辑:程序博客网 时间:2024/05/12 04:33
设置表单属性对话框:
1,添加表单页class CProp1 : public CPropertyPageclass CProp2 : public CPropertyPageclass CProp3 : public CPropertyPage注:他们分别都继承CPropertyPage2,添加属性表单class CPropSheet : public CPropertySheet注:继承自CPropertySheet.在CPropSheet的构造函数里面添加AddPageCPropSheet::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);}3.在View的菜单里面添加属性菜单并添加事件的触发OnPropertysheet():void CDialoge81View::OnPropertysheet() { //创建属性表单与属性表单页CPropSheet propSheet("测试");propSheet.DoModal();}
设置向导对话框:
1.先看一下效果图
2.实现要求
(1)第一页只能有下一步,第二页有上一步与下一步,第三页有上一步与完成的按钮
(2)各页的选项不能为空
(3)当点击完成之后将所欲选中的信息输出
3.具体实现如下:
CProp1的代码实现如下:
定义变量:intm_occipation;Cstring m_workaddr;//设置有效的控件BOOL CProp1::OnSetActive() {// TODO: Add your specialized code here and/or call the base class//设置向导中的控件((CPropSheet*)GetParent())->SetWizardButtons(PSWIZB_NEXT);return CPropertyPage::OnSetActive();}//当点击下一步是触发的时间,此函数为虚函数LRESULT CProp1::OnWizardNext() {// TODO: Add your specialized code here and/or call the base classUpdateData();//判断职业是否为空if (m_occipation==-1){AfxMessageBox("请选择你的职业!");return -1;}//判断工作地点是否为空if (m_workaddr==""){MessageBox("请选择你的工作地点!");return -1;}return CPropertyPage::OnWizardNext();}BOOL CProp1::OnInitDialog() {CPropertyPage::OnInitDialog();// TODO: Add extra initialization here//添加ListBox的下拉列表项((CListBox*)GetDlgItem(IDC_LIST1))->AddString("北京");((CListBox*)GetDlgItem(IDC_LIST1))->AddString("上海");((CListBox*)GetDlgItem(IDC_LIST1))->AddString("天津");return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE}
CProp2的代码实现:
定义变量:BOOLm_football;BOOLm_basketball;BOOLm_valleyball;BOOLm_swim;//设置有效的控件BOOL CProp2::OnSetActive() {// TODO: Add your specialized code here and/or call the base classreturn CPropertyPage::OnSetActive();}LRESULT CProp2::OnWizardNext() {// TODO: Add your specialized code here and/or call the base classUpdateData();if (m_football || m_basketball || m_valleyball || m_swim){return CPropertyPage::OnWizardNext();}else{MessageBox("请选择你的兴趣爱好!");return -1;}}
CProp3的代码实现:
定义的变量:CString m_cStrSlary;//设置有效的控件BOOL CProp3::OnSetActive() {// TODO: Add your specialized code here and/or call the base class((CPropSheet*)GetParent())->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);return CPropertyPage::OnSetActive();}//初始化时设置下来列表的值BOOL CProp3::OnInitDialog() {CPropertyPage::OnInitDialog();// TODO: Add extra initialization here//添加列表框的值((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1000以下");((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1000-2000");((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("2000-3000");((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("3000以上");//设置默认的索引((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE}//当点击完成按钮时触发的消息BOOL CProp3::OnWizardFinish() {// TODO: Add your specialized code here and/or call the base classint index;index=((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCurSel();((CComboBox*)GetDlgItem(IDC_COMBO1))->GetLBText(index,m_cStrSlary);return CPropertyPage::OnWizardFinish();}
CPropSheet的代码实现:
定义变量:public:CProp1 m_prop1;CProp2 m_prop2;CProp3 m_prop3;//构造函数的初始化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);}
view里面的代码实现:
定义的变量:private:int m_occupation;CString m_strWorkAddr;BOOL m_bLike[4];CString m_strSalary;变量的初始化m_occupation=-1;m_strWorkAddr="";memset(m_bLike,0,sizeof(m_bLike));m_strSalary="";//获取提交时的值void CDialoge81View::OnDraw(CDC* pDC){CDialoge81Doc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereCFont font;font.CreatePointFont(300,"华文行楷");CFont *pOldFont;pOldFont=pDC->SelectObject(&font);CString strTemp;strTemp="你的职业是:";switch(m_occupation){case 0:strTemp+="程序员";break;case 1:strTemp+="系统工程师";break;case 2:strTemp+="项目经理";break;default:break;}pDC->TextOut(0,0,strTemp);strTemp="你的工作地点是:";strTemp+=m_strWorkAddr;TEXTMETRIC tm;pDC->GetTextMetrics(&tm);pDC->TextOut(0,tm.tmHeight,strTemp);strTemp="你的兴趣爱好:";if (m_bLike[0]){strTemp+="足球";}if (m_bLike[1]){strTemp+="篮球";}if (m_bLike[2]){strTemp+="排球";}if (m_bLike[3]){strTemp+="游泳";}pDC->TextOut(0,tm.tmHeight*2,strTemp);strTemp="你的薪资水平:";strTemp+=m_strSalary;pDC->TextOut(0,tm.tmHeight*3,strTemp);pDC->SelectObject(pOldFont);}//设置控件的触发消息void CDialoge81View::OnPropertysheet() {// TODO: Add your command handler code here/*=================================================*//*//创建属性表单与属性表单页CPropSheet propSheet("测试");propSheet.DoModal();*//*=================================================*///创建向导表单CPropSheet propSheet("测试");propSheet.SetWizardMode();//判断是否点击完成if (ID_WIZFINISH==propSheet.DoModal()){m_occupation=propSheet.m_prop1.m_occipation;m_strWorkAddr=propSheet.m_prop1.m_workaddr;m_bLike[0]=propSheet.m_prop2.m_football;m_bLike[1]=propSheet.m_prop2.m_basketball;m_bLike[2]=propSheet.m_prop2.m_valleyball;m_bLike[3]=propSheet.m_prop2.m_swim; m_strSalary=propSheet.m_prop3.m_cStrSlary;Invalidate();}}
- MFC对话框(二)
- MFC之对话框(二)
- 【二】MFC对话框的等比例缩放
- 再探MFC(二)多标签对话框
- MFC 基础知识:主对话框与子对话框(二)
- MFC对话框
- mfc 对话框
- MFC对话框
- MFC对话框
- MFC对话框
- MFC 对话框
- MFC--对话框
- MFC 对话框
- MFC 对话框
- MFC对话框
- MFC 对话框
- MFC对话框
- mfc 对话框
- MFC学习之 树控件加图标
- LUN---Logical Unit Number
- 瞧瞧苹果OS X如何干掉Linux
- Java线程_01
- #import、#include和@class的区别
- MFC对话框(二)
- vim 之 模式匹配
- matlab实现主成分分析代码
- QQ回收
- cocos2d-x学习笔记:如何将win32移植到android
- 基础的粒子群算法代码
- Whitespace is not allowed after end of MarkupExtension 解决办法
- 跟我学习GNU Emacs - 10
- 在MYSQL里 段错误 (core dumped)是什么原因?如何解决