简单计算器代码(MFC).docx_第1页
简单计算器代码(MFC).docx_第2页
简单计算器代码(MFC).docx_第3页
简单计算器代码(MFC).docx_第4页
简单计算器代码(MFC).docx_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

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

文档简介

/ changjiangDlg.cpp : implementation file/#include stdafx.h#include changjiang.h#include changjiangDlg.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogpublic: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_MSGDECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD)/AFX_DATA_INIT(CAboutDlg)/AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CAboutDlg)/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg, CDialog)/AFX_MSG_MAP(CAboutDlg)/ No message handlers/AFX_MSG_MAPEND_MESSAGE_MAP()/ CChangjiangDlg dialogCChangjiangDlg:CChangjiangDlg(CWnd* pParent /*=NULL*/): CDialog(CChangjiangDlg:IDD, pParent)/AFX_DATA_INIT(CChangjiangDlg)xianshi = _T();/AFX_DATA_INIT/ Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CChangjiangDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CChangjiangDlg)DDX_Text(pDX, IDC_EDIT1, xianshi);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CChangjiangDlg, CDialog)/AFX_MSG_MAP(CChangjiangDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()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_BUTTON7, OnButton7)ON_BN_CLICKED(IDC_BUTTON12, OnButton12)ON_BN_CLICKED(IDC_BUTTON5, OnButton5)ON_BN_CLICKED(IDC_BUTTON8, OnButton8)ON_BN_CLICKED(IDC_BUTTON14, OnButton14)ON_BN_CLICKED(IDC_BUTTON6, OnButton6)ON_BN_CLICKED(IDC_BUTTON9, OnButton9)ON_BN_CLICKED(IDC_BUTTON16, OnButton16)ON_BN_CLICKED(IDC_BUTTON10, OnButton10)ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)ON_BN_CLICKED(IDC_BUTTON17, OnButton17)ON_BN_CLICKED(IDC_BUTTON15, OnButton15)ON_BN_CLICKED(IDC_BUTTON13, OnButton13)ON_BN_CLICKED(IDC_BUTTON18, OnButton18)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CChangjiangDlg message handlersBOOL CChangjiangDlg: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 CChangjiangDlg: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 CChangjiangDlg: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.CChangjiangDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;double data_x = 0,data_y = 0;int flag = 0;void CChangjiangDlg:OnButton1() xianshi += 7;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton2() xianshi += 8;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton3() xianshi += 9;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton4() xianshi += 4;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton7() xianshi += 5;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton12() xianshi += 6;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton5() xianshi += 1;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton8() xianshi += 2;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton14() xianshi += 3;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton6() xianshi += 0;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton9() xianshi += .;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton16() char str30;strcpy(str,(LPSTR)(LPCTSTR)xianshi);data_x = atof(str);flag = 1;xianshi = ;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnButton10() char str30;strcpy(str,(LPSTR)(LPCTSTR)xianshi);data_y = atof(str);double ans = 0;switch(flag)case 1: ans = data_x + data_y;break;case 2:ans = data_x - data_y;break;case 3:ans = data_x * data_y;break;case 4:if(data_y != 0)ans = data_x / data_y;break;char S20;gcvt(ans,15,S);xianshi = S;UpdateData(FALSE);/ TODO: Add your control notification handler code herevoid CChangjiangDlg:OnChangeEdit1() UpdateData(TRUE);/ 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 herevoid CChangjiangDlg:OnButton17() char str30;strc

温馨提示

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

评论

0/150

提交评论