MFC设计简单的计算器.doc_第1页
MFC设计简单的计算器.doc_第2页
MFC设计简单的计算器.doc_第3页
MFC设计简单的计算器.doc_第4页
MFC设计简单的计算器.doc_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

石家庄经济学院实 验 报 告学 院: 专 业: 计算机 信息工程学院计算机实验中心制Windows程序设计实验报告姓名学号 日期实验室计算机软件技术实验 指导教师设备编号实验题目实验9 对话框一、实验目的1. 掌握对话框类的定义及使用2. 掌握对话框的数据交换和检验2、 实验内容1. 编写一个基于对话框的程序,当用户点击对话框上的按钮时弹出一个模态对话框,显示的对话框中央显示出当前时间。程序界面如下图所示:2. 试着编写一个可以完成计算器的基于对话框的应用程序,该应用程序具有“加”、“减”、“乘”、“除”的功能三、源代码及实验结果1 显示时间核心代码:class CMydialog : public CDialog/ Constructionpublic:CMydialog(CWnd* pParent = NULL); / standard constructor/ Dialog Data/AFX_DATA(CMydialog)enum IDD = IDD_DIALOG1 ;CStringm_time;/AFX_DATA/ Overrides/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CMydialog)protected:virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV support/AFX_VIRTUAL/ Implementationprotected:/ Generated message map functions/AFX_MSG(CMydialog)afx_msg void On_OK();afx_msg void On_Cancel();/AFX_MSGDECLARE_MESSAGE_MAP();CMydialog:CMydialog(CWnd* pParent /*=NULL*/): CDialog(CMydialog:IDD, pParent)/AFX_DATA_INIT(CMydialog)m_time = _T();/AFX_DATA_INITvoid CMydialog:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CMydialog)DDX_Text(pDX, IDC_STATIC1, m_time);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CMydialog, CDialog)/AFX_MSG_MAP(CMydialog)ON_BN_CLICKED(IDC_BUTTON1, On_OK)ON_BN_CLICKED(IDC_BUTTON2, On_Cancel)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CMydialog message handlersvoid CMydialog:On_OK() / TODO: Add your control notification handler code hereCDialog:OnOK();void CMydialog:On_Cancel() / TODO: Add your control notification handler code hereCDialog:OnCancel();void CTest10_1Dlg:OnButton1() / TODO: Add your control notification handler code hereCTime time = CTime:GetCurrentTime();CMydialog dlg;dlg.m_time = time.Format(%Y-%m-%d %H:%M:%S);UpdateData(FALSE);dlg.DoModal();结果:图一2 计算器核心代码:CTest10_2Dlg:CTest10_2Dlg(CWnd* pParent /*=NULL*/): CDialog(CTest10_2Dlg:IDD, pParent)num1 = 0;num2 = 0;/AFX_DATA_INIT(CTest10_2Dlg)/m_result = _T();m_result.Format(%g,num1);/AFX_DATA_INIT/ Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()-LoadIcon(IDI_ICON1);e = 0;operate = N;_Flag = FALSE;DotFlag = FALSE;void CTest10_2Dlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CTest10_2Dlg)DDX_Text(pDX, IDC_EDIT1, m_result);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CTest10_2Dlg, CDialog)/AFX_MSG_MAP(CTest10_2Dlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON0, OnButton0)ON_BN_CLICKED(IDC_BUTTON1, OnButton1)ON_BN_CLICKED(IDC_BUTTON2, OnButton2)ON_BN_CLICKED(IDC_BUTTON3, OnButton3)ON_BN_CLICKED(IDC_BUTTON4, OnButton4)ON_BN_CLICKED(IDC_BUTTON5, OnButton5)ON_BN_CLICKED(IDC_BUTTON6, OnButton6)ON_BN_CLICKED(IDC_BUTTON7, OnButton7)ON_BN_CLICKED(IDC_BUTTON8, OnButton8)ON_BN_CLICKED(IDC_BUTTON9, OnButton9)ON_BN_CLICKED(IDC_BUTTON00, OnButton00)ON_BN_CLICKED(IDC_DOT, OnDot)ON_BN_CLICKED(IDC_BUTTON_, OnButton)ON_BN_CLICKED(IDC_ADD, OnAdd)ON_BN_CLICKED(IDC_MINUS, OnMinus)ON_BN_CLICKED(IDC_MUL, OnMul)ON_BN_CLICKED(IDC_DIV, OnDiv)ON_BN_CLICKED(IDC_COUNT, OnCount)/AFX_MSG_MAPEND_MESSAGE_MAP()void CTest10_2Dlg:OnButton0() / TODO: Add your control notification handler code herePress(0);void CTest10_2Dlg:OnButton1() / TODO: Add your control notification handler code herePress(1);void CTest10_2Dlg:OnButton2() / TODO: Add your control notification handler code herePress(2);void CTest10_2Dlg:OnButton3() / TODO: Add your control notification handler code herePress(3);void CTest10_2Dlg:OnButton4() / TODO: Add your control notification handler code herePress(4);void CTest10_2Dlg:OnButton5() / TODO: Add your control notification handler code herePress(5);void CTest10_2Dlg:OnButton6() / TODO: Add your control notification handler code herePress(6);void CTest10_2Dlg:OnButton7() / TODO: Add your control notification handler code herePress(7);void CTest10_2Dlg:OnButton8() / TODO: Add your control notification handler code herePress(8);void CTest10_2Dlg:OnButton9() / TODO: Add your control notification handler code herePress(9);void CTest10_2Dlg:OnButton00() / TODO: Add your control notification handler code here/Flag00 = TRUE;Press(0);Press(0);void CTest10_2Dlg:OnDot() / TODO: Add your control notification handler code hereDotFlag = TRUE;void CTest10_2Dlg:OnButton() / TODO: Add your control notification handler code here/operate = n;m_result = -;UpdateData(FALSE);_Flag = TRUE;void CTest10_2Dlg:OnAdd() / TODO: Add your control notification handler code hereoperate = +;DotFlag = FALSE;_Flag = FALSE;void CTest10_2Dlg:OnMinus() / TODO: Add your control notification handler code hereoperate = -;DotFlag = FALSE;_Flag = FALSE;void CTest10_2Dlg:OnMul() / TODO: Add your control notification handler code hereoperate = *;DotFlag = FALSE;_Flag = FALSE;void CTest10_2Dlg:OnDiv() / TODO: Add your control notification handler code hereoperate = /;DotFlag = FALSE;_Flag = FALSE;void CTest10_2Dlg:OnCount() / TODO: Add your control notification handler code hereswitch(operate)case +:num1 += num2;break;case -:num1 -= num2;break;case *:num1 *= num2;break;case /:if(num2 = 0)MessageBox(除数不可以是0!);return;num1 /= num2;break;case n:num1 = 0 - num2;break;case N:break;m_result.Format(%g,num1);UpdateData(FALSE);DotFlag = FALSE;_Flag = FALSE;num1 = 0;num2 = 0;e = 0;operate = N;void CTest10_2Dlg:Press(int n)if(DotFlag) if(operate = N) if(n) if(_Flag)num1 -= n*pow(0.1,e);else num1 += n*pow(0.1,e);m_result.Format(%g,num1); elseUpdateData(TRUE);m_result += 0; else if(_Flag)num2 -= n*pow(0.1,e); num2 += n*pow(0.1,e);m_result.Format(%g,num2); else if(operate = N) num1 *= 10;if(_Flag)num1 -= n;elsenum1 += n;m_result.Format(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论