MFC_对话框之时间显示与计算器设计.doc_第1页
MFC_对话框之时间显示与计算器设计.doc_第2页
MFC_对话框之时间显示与计算器设计.doc_第3页
MFC_对话框之时间显示与计算器设计.doc_第4页
MFC_对话框之时间显示与计算器设计.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

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

文档简介

石家庄经济学院实 验 报 告学 院: 信息工程学院 专 业: 计算机科学与技术 信息工程学院计算机实验中心制Windows程序设计实验报告姓名 范坤鹤学号 409109070315日期实验室计算机软件技术实验 指导教师刘永伟设备编号实验题目实验9 对话框一、实验目的1. 掌握对话框类的定义及使用2. 掌握对话框的数据交换和检验2、 实验内容1. 编写一个基于对话框的程序,当用户点击对话框上的按钮时弹出一个模态对话框,显示的对话框中央显示出当前时间。程序界面如下图所示:Ctime 获得当前时间的类2. 试着编写一个可以完成计算器的基于对话框的应用程序,该应用程序具有“加”、“减”、“乘”、“除”的功能三、源代码及实验结果 1、用户点击对话框上的按钮时弹出一个模态对话框的源代码:void CMy4Dlg:OnButton1() / TODO: Add your control notification handler code hereCMyDialog dig;dig.DoModal();BOOL CMyDialog:OnInitDialog() CDialog:OnInitDialog();/ TODO: Add extra initialization hereCTime t=CTime:GetCurrentTime();time=t.Format( The current time is:n %Y-%m-%d %H:%M:%S);/time.Format(%d,t.GetYear();UpdateData(FALSE);return TRUE; / return TRUE unless you set the focus to a control / EXCEPTION: OCX Property Pages should return FALSE 2、用户点击对话框上的按钮时弹出一个模态对话框的结果:(图一)图一3、 计算器源代码class CMy2Dlg : public CDialog/ Constructionpublic:void Calc(int h);void OnNumBtn(int B);double AddDecimal(double btnum);int PointPosition;BOOL judge_firstNum;BOOL judge_first;int CALCU_CHAR;double num2;double num1;CMy2Dlg(CWnd* pParent = NULL);/ standard constructorBOOL CMy2Dlg: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 AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ Set the icon for this dialog. The framework does this automatically/ when the applications main window is not a dialogSetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);/ Set small icon/ TODO: Add extra initialization herereturn TRUE; / return TRUE unless you set the focus to a controlvoid CMy2Dlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialog: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,/ this is automatically done for you by the framework.void CMy2Dlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangleint 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 icondc.DrawIcon(x, y, m_hIcon);elseCDialog:OnPaint();/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CMy2Dlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;void CMy2Dlg:OnBtn0() / TODO: Add your control notification handler code hereOnNumBtn(0);void CMy2Dlg:OnBtn00() / TODO: Add your control notification handler code hereOnNumBtn(0);OnNumBtn(0);void CMy2Dlg:OnBtn7() / TODO: Add your control notification handler code hereOnNumBtn(7);void CMy2Dlg:OnBtn8() / TODO: Add your control notification handler code hereOnNumBtn(8);void CMy2Dlg:OnBtn9() / TODO: Add your control notification handler code hereOnNumBtn(9);void CMy2Dlg:OnCheng() / TODO: Add your control notification handler code hereCalc(IDC_CHENG);void CMy2Dlg:OnBtn4() / TODO: Add your control notification handler code hereOnNumBtn(4);void CMy2Dlg:OnBtn5() / TODO: Add your control notification handler code hereOnNumBtn(5);void CMy2Dlg:OnBtn6() / TODO: Add your control notification handler code hereOnNumBtn(6);void CMy2Dlg:OnChu() / TODO: Add your control notification handler code hereCalc(IDC_CHU);void CMy2Dlg:OnBtn1() / TODO: Add your control notification handler code hereOnNumBtn(1);void CMy2Dlg:OnBtn2() / TODO: Add your control notification handler code hereOnNumBtn(2);void CMy2Dlg:OnBtn3() / TODO: Add your control notification handler code hereOnNumBtn(3);void CMy2Dlg:OnJian() / TODO: Add your control notification handler code hereCalc(IDC_JIAN);void CMy2Dlg:OnBtnpoint() / TODO: Add your control notification handler code hereif (PointPosition = 0)PointPosition = 1;void CMy2Dlg:OnPlus() / TODO: Add your control notification handler code hereCalc(IDC_PLUS);void CMy2Dlg:OnBtnsign() / TODO: Add your control notification handler code hereUpdateData(TRUE);m_num = 0 - m_num;UpdateData(FALSE);void CMy2Dlg:OnOK() / TODO: Add extra validation hereUpdateData(TRUE);num2 = m_num;switch(CALCU_CHAR)case IDC_PLUS:num1 = num1 + num2;break;case IDC_JIAN:num1 = num1 - num2;break;case IDC_CHENG:num1 = num1 * num2;break;case IDC_CHU:num1 = num1 / num2;break;default:break;m_num = num1;UpdateData(FALSE);if (CALCU_CHAR = IDC_CHU & num2 = 0)SetDlgItemText(IDC_EDIT1,除数不能为0);num2 = 0;CALCU_CHAR = 0;judge_firstNum = true;judge_first = true;PointPosition = 0;/CDialog:OnOK();double CMy2Dlg:AddDecimal(double btnum)int i = PointPosition;while(i)btnum = btnum / 10;i-;PointPosition+;return btnum;void CMy2Dlg:OnNumBtn(int B)if (judge_firstNum)m_num = B;judge_firstNum = false;else if (PointPosition)/判断小数点是否出现,UpdateData(TRUE);m_num = m_num + AddDecimal(B);elseUpdateData(TRUE);m_num = m_num * 10 + B;char * buf = new char;itoa(B,buf,10); /把字符串buf转换为整数BUpdateData(FALSE);void CMy2Dlg:Calc(int h)if (judge_first)UpdateData(TRUE);num1 = m_num;elseOnOK();judge_first = false;judge_firstNum = true;PointPositio

温馨提示

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

评论

0/150

提交评论