3.2 步骤3添加控件关联变量 IDC COMBo CComboBox m Combo IDC SEXI CButton m radio IDC EDIT CString m edit 步骤4显示对话框 菜单响应函数 void CDialogview:: OnViewModaldialogo CDialogModal m DIg m Dig DoModal
步骤3 添加控件关联变量 3.2 IDC_COMBO CComboBox m_Combo; IDC_SEX1 CButton m_Radio; IDC_EDIT CString m_Edit; 步骤4 显示对话框 1. 菜单响应函数 void CDialogView::OnViewModaldialog() { CDialogModal m_Dlg; m_Dlg.DoModal(); }
3.2 2.对话框响应函数 BOOL CDialogModal: OnlnitDialogo CDialog: OnInit Dialogo l/ TODO: Add extra initialization here m Radio. Setcheck (1) ∥把"男"设置为默认值 m Combo. InsertString(0,"小学");∥往 Combo box加入选项 m Combo. Insert String(1,"初中"); m Combo. Insert String(2,"高中"); m Combo. Insert String(3,"大学") m Combo. Insert String(4,"本科以上."); m Combo. SecUr Sel(O) ∥把"小学"设置为默认值 return TRUE; l/return TRUE unless you set the focus to a control //EXCEPTION: OCX Property Pages should return FALSE
3.2 2. 对话框响应函数 BOOL CDialogModal::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_Radio.SetCheck(1); //把"男"设置为默认值 m_Combo.InsertString(0,"小学"); //往Combo Box加入选项 m_Combo.InsertString(1,"初中"); m_Combo.InsertString(2,"高中"); m_Combo.InsertString(3,"大学"); m_Combo.InsertString(4,"本科以上..."); m_Combo.SetCurSel(0); //把"小学"设置为默认值 return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void CDialogModal: OnOko 3.2 //TODO: Add your control notification handler code here CString str str Empty if(m Radio. Getchecko) st+="先生"; else st+="小姐"; str+="你好,你的爱好:"; BOOL flag=0 C Button p, ∥|到指向 IIDC INSTEREST1的指针 p=(CButton ")GetDIgltem(IDC INSTEREST1) fp-> Getchecko)∥判断"登山"是否被选中 st+="登山"; flag =1
void CDialogModal::OnOk() { // TODO: Add your control notification handler code here CString str; str.Empty(); if(m_Radio.GetCheck()) str += "先生"; else str += "小姐"; str += "你好,你的爱好:"; BOOL flag=0; CButton *p; //得到指向IDC_INSTEREST1的指针 p = (CButton *)GetDlgItem(IDC_INSTEREST1); if(p->GetCheck()) //判断"登山"是否被选中 { str += "登山 "; flag = 1; } 3.2
3.3 33非模态对话框 概念 非模态对话框弹出后,程序可以在不关闭该 对话框的情况下继续执行,在转入到应用程序其 他部分的代码时可以不需要用户做出响应。非模 态对话框一般用来显示信息,或者实时地进行 些设置
3.3 非模态对话框 3.3 概念 非模态对话框弹出后,程序可以在不关闭该 对话框的情况下继续执行,在转入到应用程序其 他部分的代码时可以不需要用户做出响应。非模 态对话框一般用来显示信息,或者实时地进行一 些设置。 返回第3章