用vc++编写计算器问题
赤沐晴子?
2024-05-28 01:11:16
最佳回答
主要程序代码:edit1dlg.cpp文件void cedit1dlg::onchangeadd1() //加数{ // todo: if th** ** a richedit control, the control will not // send th** 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 cedit *edit=(cedit*)getdlgitem(idc_add1); cstring str; edit->getwindowtext(str); int i=atoi(str); if(i==0) **box("请输入数值!");}void cedit1dlg::onok() //确定{ // todo: add extra validation here updatedata(true);// int i=getcheckedradiobutton(idc_radio1,idc_radio4); if(i==idc_radio1) //+ { m_sum=m_add1+m_add2; } if(i==idc_radio2) //- { m_sum=m_add1-m_add2; } if(i==idc_radio3) //* { m_sum=m_add1*m_add2; } if(i==idc_radio4) // / { m_sum=m_add1/m_add2; } if(i==0) { **box("请输入一种运算符"); } updatedata(false);//记住是update是e //cdialog::onok();//此处应删除!!!}void cedit1dlg::onchangeadd2() //被加数{ // todo: if th** ** a richedit control, the control will not // send th** 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 cedit *edit=(cedit*)getdlgitem(idc_add2); cstring str; edit->getwindowtext(str); int i=atoi(str); if(i==0) **box("请输入数值!");}完整程序代码:// edit1dlg.cpp : implementation file//#include "stdafx.h"#include "edit1.h"#include "edit1dlg.h"#ifdef _debug#define new debug_new#undef th**_filestatic char th**_file[] = __file__;#endif/////////////////////////////////////////////////////////////////////////////// caboutdlg dialog used for app aboutclass caboutdlg : public cdialog{public: caboutdlg();// dialog data //{{afx_data(caboutdlg) enum { idd = idd_aboutbox }; //}}afx_data // classwizard generated virtual function overrides //{{afx_virtual(caboutdlg) protected: virtual void dodataexchange(cdataexchange* pdx); // ddx/ddv support //}}afx_virtual// implementationprotected: //{{afx_msg(caboutdlg) //}}afx_msg declare_**_map()};caboutdlg::caboutdlg() : cdialog(caboutdlg::idd){ //{{afx_data_init(caboutdlg) //}}afx_data_init}void caboutdlg::dodataexchange(cdataexchange* pdx){ cdialog::dodataexchange(pdx); //{{afx_data_map(caboutdlg) //}}afx_data_map}begin_**_map(caboutdlg, cdialog) //{{afx_msg_map(caboutdlg) // no ** handlers //}}afx_msg_mapend_**_map()/////////////////////////////////////////////////////////////////////////////// cedit1dlg dialogcedit1dlg::cedit1dlg(cwnd* pparent /*=***/) : cdialog(cedit1dlg::idd, pparent){ //{{afx_data_init(cedit1dlg) m_add1 = 0.0f; m_add2 = 0.0f; m_sum = 0.0f; //}}afx_data_init // note that loadicon does not require a subsequent destroyicon in win32 m_hicon = afxgetapp()->loadicon(idr_mainframe);}void cedit1dlg::dodataexchange(cdataexchange* pdx){ cdialog::dodataexchange(pdx); //{{afx_data_map(cedit1dlg) ddx_text(pdx, idc_add1, m_add1); ddx_text(pdx, idc_add2, m_add2); ddx_text(pdx, idc_sum, m_sum); //}}afx_data_map}begin_**_map(cedit1dlg, cdialog) //{{afx_msg_map(cedit1dlg) on_wm_syscommand() on_wm_paint() on_wm_querydragicon() on_en_change(idc_add1, onchangeadd1) on_en_change(idc_add2, onchangeadd2) on_en_change(idc_sum, onchangesum) //}}afx_msg_mapend_**_map()/////////////////////////////////////////////////////////////////////////////// cedit1dlg ** handler**ool cedit1dlg::oninitdialog(){ cdialog::oninitdialog(); // add "about..." menu item to system menu. // idm_aboutbox must be in the system command range. assert((idm_aboutbox & 0xfff0) == idm_aboutbox); assert(idm_aboutbox < 0xf000); cmenu* psysmenu = getsystemmenu(false); if (psysmenu != **) { cstring straboutmenu; straboutmenu.loadstring(ids_aboutbox); if (!straboutmenu.**empty()) { psysmenu->appendmenu(mf_separator); psysmenu->appendmenu(mf_string, idm_aboutbox, straboutmenu); } } // set the icon for th** dialog. the framework does th** automatically // when the application's main window ** not a dialog seticon(m_hicon, true); // set big icon seticon(m_hicon, false); // set small icon // todo: add extra initialization here return true; // return true unless you set the focus to a control}void cedit1dlg::onsyscommand(uint nid, lparam lparam){ if ((nid & 0xfff0) == idm_aboutbox) { caboutdlg dlgabout; dlgabout.domodal(); } else { cdialog::onsyscommand(nid, lparam); }}// if you add a minimize button to your dialog, you will need the code below// to draw the icon. for mfc applications using the document/view model,// th** ** automatically done for you by the framework.void cedit1dlg::onpaint() { if (**iconic()) { cpaintdc dc(th**); // device context for painting send**(wm_iconerasebkgnd, (wparam) dc.getsafehdc(), 0); // center icon in client rectangle int cxicon = getsystemmetrics(sm_cxicon); int cyicon = getsystemmetrics(sm_cyicon); crect rect; getclientrect(&rect); int x = (rect.width() - cxicon + 1) / 2; int y = (rect.height() - cyicon + 1) / 2; // draw the icon dc.drawicon(x, y, m_hicon); } else { cdialog::onpaint(); }}// the system calls th** to obtain the cursor to d**play while the user drags// the minimized window.hcursor cedit1dlg::onquerydragicon(){ return (hcursor) m_hicon;}void cedit1dlg::onchangeadd1() { // todo: if th** ** a richedit control, the control will not // send th** 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 cedit *edit=(cedit*)getdlgitem(idc_add1); cstring str; edit->getwindowtext(str); int i=atoi(str); if(i==0) **box("请输入数值!");}void cedit1dlg::onok() { // todo: add extra validation here updatedata(true);// int i=getcheckedradiobutton(idc_radio1,idc_radio4); if(i==idc_radio1) //+ { m_sum=m_add1+m_add2; } if(i==idc_radio2) //- { m_sum=m_add1-m_add2; } if(i==idc_radio3) //* { m_sum=m_add1*m_add2; } if(i==idc_radio4) // / { m_sum=m_add1/m_add2; } if(i==0) { **box("请输入一种运算符"); } updatedata(false);//记住是update是e //cdialog::onok();//此处应删除!!!}void cedit1dlg::onchangeadd2() { // todo: if th** ** a richedit control, the control will not // send th** 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 cedit *edit=(cedit*)getdlgitem(idc_add2); cstring str; edit->getwindowtext(str); int i=atoi(str); if(i==0) **box("请输入数值!");} 20210311