简易计算器

0.准备工作

首先确保自己的vs2019能新建MFC项目,如下所示
在这里插入图片描述
如果发现自己vs2019或者其他版本的vs无法建立该项目,说明安装时没有安装相应组件,可以参考该篇文章安装相应的组件即可。VS2019/MFC组件安装步骤

1.新建MFC项目

新建项目时记住勾选相应的框,如下:
在这里插入图片描述
其余的选项默认即可,在此新工程已经建立完成,点击运行按钮,无错误无警告则说明安装与新建步骤都是正确的。
在这里插入图片描述

2.设计软件界面

选择工具箱,点中按钮和文本框,将它们拉入到界面中即可,然后根据自己喜好调整大小
在这里插入图片描述
按键上的数字需要点击属性中的caption来改变其显示的值
在这里插入图片描述
每一个按键都有其唯一的ID,该ID是后面操作其的根据。

3.软件效果

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
什么好玩做什么 namespace WindowsFormsApplication1 { public partial class Form1 : Form { Double first = 0; String second = null; int code = 0; String result = null; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button(String sender) { if (result != null) { textBox1.Clear(); } if (code != 0 && second == null) { textBox1.Clear(); } String b = sender; if (textBox1.Text == null || textBox1.Text == "") { textBox1.Text = b; } else { textBox1.Text = textBox1.Text + b; } if (code != 0) { second = textBox1.Text; } result = null; label1.Focus(); } private void button1_Click(object sender, EventArgs e) { button("1"); } private void button2_Click(object sender, EventArgs e) { button("2"); } private void button3_Click(object sender, EventArgs e) { button("3"); } private void button4_Click(object sender, EventArgs e) { button("4"); } private void button5_Click(object sender, EventArgs e) { button("5"); } private void button6_Click(object sender, EventArgs e) { button("6"); } private void button7_Click(object sender, EventArgs e) { button("7"); } private void button8_Click(object sender, EventArgs e) { button("8"); } private void button9_Click(object sender, EventArgs e) { button("9"); } private void button10_Click(object sender, EventArgs e) { if (textBox1.Text == null || textBox1.Text == "") { button("0"); }else if (Convert.ToDouble(textBox1.Text) != 0) { button("0"); }else if (textBox1.Text.IndexOf(".") == 1) { button("0"); } label1.Focus(); } private void button11_Click(object sender, EventArgs e) { if (second == null) { MessageBox.Show("哥们你要算什么啊?麻烦再输入数!"); } else if (Convert.ToDouble(second) == 0 && first != 0 && code == 4) { textBox1.Text = "除数不能为零!"; } else { switch (code) { case 1: textBox1.Text = Convert.ToString(first + Convert.ToDouble(textBox1.Text)); break; case 2: textBox1.Text = Convert.ToString(first - Convert.ToDouble(textBox1.Text)); break; case 3: textBox1.Text = Convert.ToString(first * Convert.ToDouble(textBox1.Text)); break; case 4: textBox1.Text = Convert.ToString(first / Convert.ToDouble(textBox1.Text)); break; } } first = 0; second = null; code = 0; result = textBox1.Text; label1.Focus(); } private void button12_Click(object sender, EventArgs e) { if (Convert.ToDouble(textBox1.Text) != 0 || textBox1.Text == null || textBox1.Text == "") { button("00"); } else if (textBox1.Text.IndexOf(".") == 1) { button("00"); } label1.Focus(); } private void button17_Click(object sender, EventArgs e) { if (textBox1.Text.IndexOf(".") < 1) { button("."); } label1.Focus(); } private void button_2() { if (textBox1.Text == null || textBox1.Text == "") { first = 0; } else if (first == 0) { first = Convert.ToDouble(textBox1.Text); } } private void button18_Click(object sender, EventArgs e) { button_2(); code = 4; label1.Focus(); } private void button13_Click(object sender, EventArgs e) { button_2(); code = 2; label1.Focus(); } private void button14_Click(object sender, EventArgs e) { button_2(); code = 3; label1.Focus(); } private void button15_Click(object sender, EventArgs e) { button_2(); code = 1; label1.Focus(); } private void button16_Click(object sender, EventArgs e) { textBox1.Clear(); label1.Focus(); } private void Form1_KeyUp(object sender, KeyEventArgs e) { //MessageBox.Show(Convert.ToString(e.KeyCode)); if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Oemplus) { button11_Click(null, null); } else if (e.KeyCode == Keys.Divide || e.KeyCode == Keys.OemQuestion) { button18_Click(null, null); } else if (e.KeyCode == Keys.Add || e.KeyCode == Keys.Oemplus) { button15_Click(null, null); } else if (e.KeyCode == Keys.Multiply) { button14_Click(null, null); } else if (e.KeyCode == Keys.Subtract || e.KeyCode == Keys.OemMinus) { button13_Click(null, null); } else if (e.KeyCode == Keys.OemPeriod || e.KeyCode == Keys.Delete) { button17_Click(null, null); } else if (e.KeyCode == Keys.Oemtilde) { button12_Click(null, null); } else if (e.KeyCode == Keys.D1 || e.KeyCode == Keys.NumPad1) { button1_Click(null, null); } else if (e.KeyCode == Keys.D2 || e.KeyCode == Keys.NumPad2) { button2_Click(null, null); } else if (e.KeyCode == Keys.D3 || e.KeyCode == Keys.NumPad3) { button3_Click(null, null); } else if (e.KeyCode == Keys.D4 || e.KeyCode == Keys.NumPad4) { button4_Click(null, null); } else if (e.KeyCode == Keys.D5 || e.KeyCode == Keys.NumPad5) { button5_Click(null, null); } else if (e.KeyCode == Keys.D6 || e.KeyCode == Keys.NumPad6) { button6_Click(null, null); } else if (e.KeyCode == Keys.D7 || e.KeyCode == Keys.NumPad7) { button7_Click(null, null); } else if (e.KeyCode == Keys.D8 || e.KeyCode == Keys.NumPad8) { button8_Click(null, null); } else if (e.KeyCode == Keys.D9 || e.KeyCode == Keys.NumPad9) { button9_Click(null, null); } else if (e.KeyCode == Keys.D0 || e.KeyCode == Keys.NumPad0) { button10_Click(null, null); } } private void textBox1_Enter(object sender, EventArgs e) { label1.Focus(); } } }
课程设计报告 题目:在win32 application工程下计算 陈李元 41212204 余 斌 41212202 概述 课程设计的内容 系统需求分析 系统目标 重要功能 开发环境 设计过程 主函数WinMain设计过程 窗口过程WndProc 小结 参考文献 1:程序代码 2:程序运行部分截图 概述 课程设计的内容 c++课程设计我们组选的是设计一个带界面的计算 MFC,而是在win32 application工程下做的带界 windows程序设计范畴。 系统需求分析 系统目标 另外还具有计算N阶阶乘的功能,此外还具 。 重要功能 开发环境 visual c++ 6.0编译,链接,运行。它是在 工程下所创建。 设计过程 主函数WinMain设计过程 windows API。这 windows.h标准库中。 windows程序设计中,它必须要包含一个程序入口主 WinMain和一个过程函数WndProc。 总是以下面的形式出现。 WINAPI WinMain (HINSTANCE hInstance, WinMain第一个参数一般叫做“实例句柄”,在windows 第二个参数总是定义为NULL(定义为0) 第三个参数是用来运行程序的命令行。有些windows程 第四个参数用来指明程序最初如何显示。 1)注册窗口类 2)创建窗口 3)在桌面显示窗口 4)更新窗口客户区 5)进入无限的消息获取和处理的循环。首先是获取 WM_QUIT,则GetMessage函数返回FALSE,整 WndProc 注册: 程序设计中有许许多多的结构体。其中 是用于注册窗口类的。 窗口类型 窗口处理函数 窗口扩展 窗口实例扩展 实例句柄 窗口的最小化图标 窗口鼠标光标 窗口背景色 窗口菜单 窗口类名 : 创建窗口 CreateWindow函数 指向已注册窗口类名称的指针
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值