建立一个单文档mfc程序,设计一个菜单按钮,可以弹出一个对话框。在对话框中使用视图类和框架类中的变量。 界面如下
对话框图:
框架类的成员变量index:
视图类的成员变量m_str:
button1的响应函数
//选择下拉列表的一项,在编辑框中显示出来。其中用到index和m_strvoid CDialog1::OnBnClickedButton1(){ // TODO: 在此添加控件通知处理程序代码 //获得框架类对象指针 CMainFrame* pMain = (CMainFrame*)AfxGetApp()->m_pMainWnd; //获得框架类的成员变量index pMain->index = ((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCurSel(); //获得视图类对象指针 CMFCapplication2View* pView = (CMFCApplication2View*)pMain->GetActiveView(); //获得视图类的成员变量m_str CString str1 = pView->m_str; ((CComboBox*)GetDlgItem(IDC_COMBO1))->GetLBText(pMain->index, str1); //写入编辑框 SetDlgItemText(IDC_EDIT1, str1);}新闻热点
疑难解答