建立一個單文檔mfc程序,設(shè)計一個菜單按鈕,可以彈出一個對話框。在對話框中使用視圖類和框架類中的變量。 界面如下
對話框圖:

框架類的成員變量index:

視圖類的成員變量m_str:

button1的響應(yīng)函數(shù)
//選擇下拉列表的一項,在編輯框中顯示出來。其中用到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);}新聞熱點
疑難解答