在VC中的计算器制作,我们开始要考虑的就是简单的计算器的是由什么构成的,有按钮,有显示框。按钮有数字的0~9部分还有小数点,,外加4个运算符号加减乘除,还有就是显示结果的等于号。。可以的话可以加个清除显示结果框的按钮和倒退按钮。。

首先先电脑有vc6.0,,进入后点击文件,再新建~工程~MFC...【exe】输入工程名,

点击IDD_XX_DIALOG进入设置页面

用DEL除去软件给我们的,有这些工具在界面设置

设置后在右击按钮在属性~常规~标题中修改0~9的标记后的大概的样子

再右击显示结果的框架~~建立类向导 ,添加变量

设置完就再回到编辑 界面双击你设置的按钮的从0开始输入代码

void CMyDlg::OnButton0() 
{
m_result += _T("0");//定义宏
UpdateData(FALSE); //再清屏

};

下面的1~9包括小数点也是

设置完就对运算符先设置加号

void CMyDlg::OnButton4() 
{
n=0;//标记
data = atof(m_result);//输入的是字符串的存在要转换成数字在计算
m_result = _T(" ");

}

再设置减号,样式差不多就是其中的标记改成1,乘除也依次类推。。

这是等号的代码

void CMyDlg::OnButton6() 
{if(n==0)
{
data += atof(m_result);
m_result.Format(_T("%lf"),data);
UpdateData(FALSE);
}
if(n==1)
{
data -= atof(m_result);
m_result.Format(_T("%lf"),data);
UpdateData(FALSE);
}
if(n==2)
{
data *= atof(m_result);
m_result.Format(_T("%lf"),data);
UpdateData(FALSE);
}
if(n==3)//辨别输入的标号
{
data /= atof(m_result);//数据进行转换后也等于data=data/m_result
m_result.Format(_T("%lf"),data);//进行输出的精确取值
UpdateData(FALSE);
}

}

删除的代码是

void CMyDlg::OnButton17() 
{
m_result = _T(" ");//返回
UpdateData(FALSE);

}

void CMyDlg::OnButton18() 
{
  m_result = m_result.Left(m_result.GetLength()-1);//取总长度,再把其中的字符串减一
  UpdateData(FALSE);

}

开始定义了看图片,,不解释

可以了,运行程序

总的源代码如下

// 计算器Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "计算器.h"
#include "计算器Dlg.h"

#include<Math.h>
#include<wchar.h>
//#include<coino.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
// CAboutDlg dialog used for App About

class 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

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_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_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
m_result = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Text(pDX, IDC_EDIT1, m_result);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON13, OnButton13)
ON_BN_CLICKED(IDC_BUTTON15, OnButton15)
ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON16, OnButton16)
ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_BN_CLICKED(IDC_BUTTON17, OnButton17)
ON_BN_CLICKED(IDC_BUTTON18, OnButton18)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CMyDlg message handlers

BOOL CMyDlg::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 != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is 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 CMyDlg::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,
//  this is automatically done for you by the framework.

void CMyDlg::OnPaint() 
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(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 this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CMyDlg::OnChangeEdit1() 
{
// 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

}

void CMyDlg::OnButton1() 
{
m_result += _T("1");//unicode编译
UpdateData(FALSE);//清屏,可以重新输入

}

void CMyDlg::OnButton3() 
{
m_result += _T("2");
UpdateData(FALSE);

}

void CMyDlg::OnButton2() 
{
m_result += _T("3");
UpdateData(FALSE);

}

void CMyDlg::OnButton13() 
{
m_result += _T("4");
UpdateData(FALSE);

}

void CMyDlg::OnButton15() 
{
m_result += _T("5");
UpdateData(FALSE);

}

void CMyDlg::OnButton14() 
{
m_result += _T("6");
UpdateData(FALSE);

}

void CMyDlg::OnButton9() 
{
m_result += _T("7");
UpdateData(FALSE);

}

void CMyDlg::OnButton11() 
{
m_result += _T("8");
UpdateData(FALSE);
}

void CMyDlg::OnButton10() 
{
m_result += _T("9");
UpdateData(FALSE);
}

void CMyDlg::OnButton7() 
{
m_result += _T("0");
UpdateData(FALSE);

}

void CMyDlg::OnButton5() 
{
m_result = m_result + _T("."); 
UpdateData(FALSE);
}

void CMyDlg::OnButton6() 
{if(n==0)
{
data += atof(m_result);
m_result.Format(_T("%lf"),data);
UpdateData(FALSE);
}
if(n==1)
{
data -= atof(m_result);
m_result.Format(_T("%lf"),data);
UpdateData(FALSE);
}
if(n==2)
{
data *= atof(m_result);
m_result.Format(_T("%lf"),data);
UpdateData(FALSE);
}
if(n==3)
{
data /= atof(m_result);
m_result.Format(_T("%lf"),data);
UpdateData(FALSE);
}

}

void CMyDlg::OnButton4() 
{
n=0;
data = atof(m_result);
m_result = _T(" ");

}

void CMyDlg::OnButton16() 
{
n=1;
data = atof(m_result);
m_result = _T(" ");

}

void CMyDlg::OnButton12() 
{
n=2;
data = atof(m_result);
m_result = _T(" ");

}

void CMyDlg::OnButton8() 
{
n=3;
data = atof(m_result);
m_result = _T(" ");

}

void CMyDlg::OnButton17() 
{
m_result = _T(" ");
UpdateData(FALSE);

}

void CMyDlg::OnButton18() 
{
  m_result = m_result.Left(m_result.GetLength()-1);
  UpdateData(FALSE);

}

VC6.0的MFC简单计算器制作相关推荐

  1. VC6.0下MFC按钮点击函数手动添加

    有些vc6.0的兼容性不好,按钮双击不能自动加载函数,这时候需要手动添加按钮函数 点击类向导,再找到控件名字,点击触发消息类型,再选Add function,改好名字,就OK了

  2. 基于VC6.0用MFC编写简易计算器

    功能介绍: 1> 标准型:能进行加.减.乘.除四则运算,具有清空.回退功能,还附加了添加小数点.化为百分数的功能. 2> 科学型:新增了求三角函数(sin.cos.tan).反三角函数(a ...

  3. VC6.0 MFC 时钟运动 调用对话框设置时间

    时钟运动 源码下载链接(免费) 问题描述 在VC6.0的MFC中画一个钟表,有时针.分针.秒针,并实现时针.分针.秒针的运动. 最终部分静态效果图如下: 操作详细过程 1.新建 1.打开VC6.0,点 ...

  4. VC6.0 MFC 模拟弹簧运动(改进版)

    VC6.0 MFC 模拟弹簧运动(改进版) 一.内容描述 运用VC6.0新建工程MFC AppWizard(exe),创建单文档应用程序,画一个弹簧(用矩形代替),下面挂有重物(用圆代替),设定重物质 ...

  5. VC6.0和VS2005:C++和C#编写调用COM组件

    这篇文章就是关于COM组件的编写和调用的,主要包含了使用VC6.0编写和调用COM组件,VS2005中使用C#编写和调用COM组件,以及在VC6.0和VS2005之间互相调用COM组件. AD: 前一 ...

  6. vc6.0使用DAO访问access2000的问题

    感觉DAO已经是一种比较旧的数据库技术,但我的一个同学还在使用VC6.0跟mfc的DAO类来操作access2000,并遇到了一个问题,就是程序运行时提示说"无法识别数据库格式". ...

  7. VC6.0制作简单的avi视频播放器

    目前,专门用于设计多媒体应用的软件很多.而VC6.0也提供了一种动画控件来实现简单多媒体动画文件的播放.我们创建一个基于对话框的工程,取名为player,具体步骤如下: 图1 用MFC AppWiza ...

  8. c语言中的16进制坐标计算器,C语言实现简单计算器(VC6.0环境)

    C语言版简易计算器,包含几个小功能,而且比较精简,适合新手了解整合框架结构 源代码如下: #include #include #include //预处理指令 int main(void) { dou ...

  9. android页面布局计算机,Android Studio制作简单计算器App

    Android Studio制作简单计算器App 计算机界面如图: 程序设计步骤: (1)在布局文件中声明编辑文件框EditText,按钮Button等组件. (2)在MainActivity中获取组 ...

最新文章

  1. java 数据类型转换的一场_Java基础 — 四类八种基本数据类型
  2. 如何理解物体的6D位姿估计任务?
  3. Druid如何自动根据URL自动识别DriverClass的
  4. 【HTML+CSS】练习:百度首页模拟
  5. linux培训机构 网络班,Linux基础教程之网络基础知识与Linux网络配置
  6. CakePHP 2.10.17 发布,PHP 快速开发框架
  7. leetcode51. N 皇后(回溯算法)
  8. [国嵌笔记][036][关闭MMU和CACHE]
  9. python混沌时间序列分析_用Python进行时间序列分析
  10. 11月AI大事件回顾:GPT3开放使用/女娲视觉大模型/AE文艺复兴/...
  11. springcloud服务熔断和服务降级的自我理解
  12. 第一个Net+Mysql的例子,比想象的简单很多
  13. 关于如何理解链表结构体指针引用LinkNode * L的问题
  14. 网易2017校招合唱团
  15. 傅里叶变换后面的到底有什么小秘密?
  16. 计算机蓝屏代码0x000000ED,电脑蓝屏代码0x000000ed解决步骤
  17. Docker容器与容器云
  18. chatbot学习汇总
  19. CTFHUB http协议题目 学习笔记 详细步骤 请求方式 302跳转 cookie 基础认证 响应源代码
  20. K8S日常问题-k8s中大量pod 状态 evicted

热门文章

  1. Linux设备检测外部网络NAT类型
  2. 中南大学2019研究生复试机试题
  3. 计算机模拟基因表达,体外共培养+计算机模拟,分析合生制剂对结直肠癌细胞的影响...
  4. PyQT5 之 Qt Designer 介绍
  5. 那些成功学和鸡汤文没有告诉你的事
  6. Kotlin协程:挂起与恢复原理逆向刨析
  7. Apollo会使Mysql处于sleep状态的连接数增多
  8. 23.2.28 Staffing System
  9. 工具︱ Web3加密浏览器Brave有什么特别之处?
  10. Python—实操小实验之人机PK游戏(终极版本—应用类与对象的知识点应用)