【正文】
據(jù)的同時,重新激活第二個編輯框。如果想簡單設(shè)計的話,之前的所有編輯框隱藏和顯示函數(shù)就不用添加。:在對話框中添加兩個選擇控件:Degree和Rad,第一個選擇控件關(guān)聯(lián)變量為m_CDR,添加方法和上面添加編輯框關(guān)聯(lián)變量一樣(注意:要關(guān)聯(lián)變量必須把選擇控件屬性中的組勾選,不然找不到選擇控件的地址),并初始化為m_CDR = 0。為零時選擇框默認被選中。兩個選擇控件是互斥的,當選中Rad時m_CDR = 0,從而判斷是執(zhí)行角度制還是弧度制,然后雙擊選擇控件,添加代碼UpdateData(TRUE)。以sin(x)為例添加代碼:void CTEST1Dlg::OnSin() //正弦函數(shù)運算:sin(x){// TODO: Add your control notification handler code hereif(m_CDR == 1){m_FDR=1。 //m_CDR單選框關(guān)聯(lián)變量,角度運算}else{m_FDR=(2*PI)/360。 //弧度運算}m_EDIT3_NUM=sin(m_EDIT1_NUM*m_FDR)。GetDlgItem(IDC_EDIT2)ShowWindow(SW_HIDE)。 //在只有一個操作數(shù)時,隱藏第二個編輯框UpdateData(FALSE)。} 變量m_FDR添加方法:在右側(cè)ClassView中的CAboutDlg鼠標右擊選擇Add Member Variable….變量類型為:double,變量名為:m_FDR (3)在BOOL CTEST1Dlg::OnInitDialog()函數(shù)中加入SetWindowText(_T(計算器))。 改窗口標題為“計算器”。 (4)完成程序編寫后,編譯執(zhí)行。2 計算界面演示:加法:倒數(shù):除法:3 程序清單:include //數(shù)學(xué)函數(shù)運算頭文件define PI //宏定義π在BOOL CTEST1Dlg::OnInitDialog()函數(shù)中加入SetWindowText(_T(計算器))。 改窗口標題為“計算器”;void CTEST1Dlg::OnNO1() //第一個數(shù)字輸入框{ // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your control notification handler code here UpdateData(TRUE)。}void CTEST1Dlg::OnNO2() //第二個數(shù)字輸入框{ // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your control notification handler code here UpdateData(TRUE)。}void CTEST1Dlg::OnNO3() //運算結(jié)果顯示框{ // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your control notification handler code here UpdateData(TRUE)。}void CTEST1Dlg::OnINTR() //計算器操作說明{ // TODO: Add your control notification handler code here MessageBox(例如M+N=?,在第一個編輯框輸入M,第