C++MFC实现win10标准计算器

最近学习MFC,通过自己做一个win10版本的计算器,目前做的这个是标准计算器,这个计算器的一些逻辑运算也是根据win10标准计算器逻辑来写的,所以基于vs和标准C++的MFC实现了这个标准计算器。

功能实现

根据输入数字进行无优先级运算。 

运算功能:+,-,×,÷。

特殊功能:输入框归零(CE),全部归零(C),退格,等于。

布局特点:对字体进行了调整,数字与其他按钮大小不同,两个显示框输出数字大小不同,含有最小化窗口按钮。

效果图

界面图

 实际运算图

 CounterDlg.h代码:

 CounterDlg.h主要是定义各种变量。


// CounterDlg.h : 头文件
//

#pragma once

enum Equal_Flag {
	FLAG_JIA=1,
	FLAG_JIAN,
	FLAG_CHENG,
	FLAG_CHU,
};
// CCounterDlg 对话框
class CCounterDlg : public CDialogEx
{
// 构造
public:
	CCounterDlg(CWnd* pParent = NULL);	// 标准构造函数
	void SaveFirstValue();
	void SaveSecondValue();
	void Equal();
	void Clear();
	void Clear1();

	CFont	fontButton;
	CFont	fontButton1;
	CFont	fontFirstshow;
	CFont	fontSecondshow;

// 对话框数据
	enum { IDD = IDD_COUNTER_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持


// 实现
protected:
	HICON m_hIcon;

	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnBnClickedButnum0();
	afx_msg void OnBnClickedButnum1();
	afx_msg void OnBnClickedButnum2();
	afx_msg void OnBnClickedButnum3();
	afx_msg void OnBnClickedButnum4();
	afx_msg void OnBnClickedButnum5();
	afx_msg void OnBnClickedButnum6();
	afx_msg void OnBnClickedButnum7();
	afx_msg void OnBnClickedButnum8();
	afx_msg void OnBnClickedButnum9();
	afx_msg void OnBnClickedButpoint();
	afx_msg void OnBnClickedButsign();
	afx_msg void OnBnClickedButadd();
	afx_msg void OnBnClickedButdel();
	afx_msg void OnBnClickedButcheng();
	afx_msg void OnBnClickedButchu();
	afx_msg void OnBnClickedButback();
	afx_msg void OnBnClickedButclear();
	afx_msg void OnBnClickedButclear1();
	afx_msg void OnBnClickedButsin();
	afx_msg void OnBnClickedButcos();
	afx_msg void OnBnClickedButtan();
	afx_msg void OnBnClickedButpf();
	afx_msg void OnEnChangeEditShow();
	afx_msg void OnEnChangeEditShow1();
	afx_msg void OnBnClickedButequal();
public:

	CString m_str;		//第一个屏幕变量
	CString m_str1;		//第二个屏幕变量
	CString m_str2;		//屏幕变量

	double m_Num1;		//运算中的第一个变量
	double m_Num2;		//
	double m_Num3;		//后续输入存值空间
	double m_Result;		//结果值

	Equal_Flag mFlag;

};

 CounterDlg.cpp代码


// CounterDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "Counter.h"
#include "CounterDlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

	// 对话框数据
	enum { IDD = IDD_ABOUTBOX };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CCounterDlg 对话框



CCounterDlg::CCounterDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CCounterDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

void CCounterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_SHOW1, m_str1);
}

BEGIN_MESSAGE_MAP(CCounterDlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTNum0, &CCounterDlg::OnBnClickedButnum0)
	ON_BN_CLICKED(IDC_BUTNum1, &CCounterDlg::OnBnClickedButnum1)
	ON_BN_CLICKED(IDC_BUTNum2, &CCounterDlg::OnBnClickedButnum2)
	ON_BN_CLICKED(IDC_BUTNum3, &CCounterDlg::OnBnClickedButnum3)
	ON_BN_CLICKED(IDC_BUTNum4, &CCounterDlg::OnBnClickedButnum4)
	ON_BN_CLICKED(IDC_BUTNum5, &CCounterDlg::OnBnClickedButnum5)
	ON_BN_CLICKED(IDC_BUTNum6, &CCounterDlg::OnBnClickedButnum6)
	ON_BN_CLICKED(IDC_BUTNum7, &CCounterDlg::OnBnClickedButnum7)
	ON_BN_CLICKED(IDC_BUTNum8, &CCounterDlg::OnBnClickedButnum8)
	ON_BN_CLICKED(IDC_BUTNum9, &CCounterDlg::OnBnClickedButnum9)
	ON_BN_CLICKED(IDC_BUTPoint, &CCounterDlg::OnBnClickedButpoint)
	ON_BN_CLICKED(IDC_BUTSign, &CCounterDlg::OnBnClickedButsign)
	ON_BN_CLICKED(IDC_BUTADD, &CCounterDlg::OnBnClickedButadd)
	ON_BN_CLICKED(IDC_BUTDEL, &CCounterDlg::OnBnClickedButdel)
	ON_BN_CLICKED(IDC_BUTCHENG, &CCounterDlg::OnBnClickedButcheng)
	ON_BN_CLICKED(IDC_BUTCHU, &CCounterDlg::OnBnClickedButchu)
	ON_BN_CLICKED(IDC_BUTBACK, &CCounterDlg::OnBnClickedButback)
	ON_BN_CLICKED(IDC_BUTClear, &CCounterDlg::OnBnClickedButclear)
	ON_BN_CLICKED(IDC_BUTClear1, &CCounterDlg::OnBnClickedButclear1)
	ON_BN_CLICKED(IDC_BUTSin, &CCounterDlg::OnBnClickedButsin)
	ON_BN_CLICKED(IDC_BUTCos, &CCounterDlg::OnBnClickedButcos)
	ON_BN_CLICKED(IDC_BUTTan, &CCounterDlg::OnBnClickedButtan)
	ON_BN_CLICKED(IDC_BUTPF, &CCounterDlg::OnBnClickedButpf)
	ON_EN_CHANGE(IDC_EDIT_SHOW, &CCounterDlg::OnEnChangeEditShow)
	ON_EN_CHANGE(IDC_EDIT_SHOW1, &CCounterDlg::OnEnChangeEditShow1)
	ON_BN_CLICKED(IDC_BUTEqual, &CCounterDlg::OnBnClickedButequal)
END_MESSAGE_MAP()


// CCounterDlg 消息处理程序

BOOL CCounterDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO:  在此添加额外的初始化代码
	fontButton.CreatePointFont(150, "Arial Black", NULL);
	fontButton1.CreatePointFont(150, "宋体", NULL);
	fontFirstshow.CreatePointFont(200, "宋体", NULL);
	fontSecondshow.CreatePointFont(100, "宋体", NULL);

	GetDlgItem(IDC_BUTNum1)->SetFont(&fontButton);
	GetDlgItem(IDC_BUTNum2)->SetFont(&fontButton);
	GetDlgItem(IDC_BUTNum3)->SetFont(&fontButton);
	GetDlgItem(IDC_BUTNum4)->SetFont(&fontButton);
	GetDlgItem(IDC_BUTNum5)->SetFont(&fontButton);
	GetDlgItem(IDC_BUTNum6)->SetFont(&fontButton);
	GetDlgItem(IDC_BUTNum7)->SetFont(&fontButton);
	GetDlgItem(IDC_BUTNum8)->SetFont(&fontButton);
	GetDlgItem(IDC_BUTNum9)->SetFont(&fontButton);
	GetDlgItem(IDC_BUTNum0)->SetFont(&fontButton);
	GetDlgItem(IDC_BUTADD)->SetFont(&fontButton1);
	GetDlgItem(IDC_BUTDEL)->SetFont(&fontButton1);
	GetDlgItem(IDC_BUTCHENG)->SetFont(&fontButton1);
	GetDlgItem(IDC_BUTCHU)->SetFont(&fontButton1);
	GetDlgItem(IDC_BUTBACK)->SetFont(&fontButton1);
	GetDlgItem(IDC_BUTClear)->SetFont(&fontButton1);
	GetDlgItem(IDC_BUTClear1)->SetFont(&fontButton1);
	//GetDlgItem(IDC_BUTSin)->SetFont(&fontButton1);
	//GetDlgItem(IDC_BUTCos)->SetFont(&fontButton1);
	//GetDlgItem(IDC_BUTTan)->SetFont(&fontButton1);
	//GetDlgItem(IDC_BUTPF)->SetFont(&fontButton1);
	GetDlgItem(IDC_BUTSign)->SetFont(&fontButton1);
	GetDlgItem(IDC_BUTEqual)->SetFont(&fontButton1);
	GetDlgItem(IDC_EDIT_SHOW)->SetFont(&fontFirstshow);
	GetDlgItem(IDC_EDIT_SHOW1)->SetFont(&fontSecondshow);

	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}

void CCounterDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。

void CCounterDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		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;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CCounterDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}



void CCounterDlg::OnBnClickedButnum0()
{
	// TODO:  在此添加控件通知处理程序代码
	double str = 0.0f;
	if (0 == m_str.Find(L' '))
	{
		m_str = "";
	}
	if (-1 == m_str.Find(L'.'))
	{
		str = atof(m_str);
		if (str == 0)
		{
			m_str = m_str.Left(m_str.GetAllocLength() - 1);
		}
	}
	m_str = m_str + _T("0");
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButnum1()
{
	// TODO:  在此添加控件通知处理程序代码

	if (0 == m_str.Find(L' '))
	{
		m_str = "";
	}

	m_str = m_str + _T("1");
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButnum2()
{
	// TODO:  在此添加控件通知处理程序代码
	if (0 == m_str.Find(L' '))
	{
		m_str = "";
	}

	m_str = m_str + _T("2");
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButnum3()
{
	// TODO:  在此添加控件通知处理程序代码
	if (0 == m_str.Find(L' '))
	{
		m_str = "";
	}

	m_str = m_str + _T("3");
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButnum4()
{
	// TODO:  在此添加控件通知处理程序代码
	if (0 == m_str.Find(L' '))
	{
		m_str = "";
	}

	m_str = m_str + _T("4");
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButnum5()
{
	// TODO:  在此添加控件通知处理程序代码
	if (0 == m_str.Find(L' '))
	{
		m_str = "";
	}

	m_str = m_str + _T("5");
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButnum6()
{
	// TODO:  在此添加控件通知处理程序代码
	if (0 == m_str.Find(L' '))
	{
		m_str = "";
	}

	m_str = m_str + _T("6");
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButnum7()
{
	// TODO:  在此添加控件通知处理程序代码
	if (0 == m_str.Find(L' '))
	{
		m_str = "";
	}

	m_str = m_str + _T("7");
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButnum8()
{
	// TODO:  在此添加控件通知处理程序代码
	if (0 == m_str.Find(L' '))
	{
		m_str = "";
	}

	m_str = m_str + _T("8");
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButnum9()
{
	// TODO:  在此添加控件通知处理程序代码
	if (0 == m_str.Find(L' '))
	{
		m_str = "";
	}

	m_str = m_str + _T("9");
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButpoint()
{
	// TODO:  在此添加控件通知处理程序代码
	if (-1 == m_str.Find(L'.'))
	{
		m_str = m_str + _T('.');
	}
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::OnBnClickedButsign()
{
	// TODO:  在此添加控件通知处理程序代码
	double str;
	str = atof(m_str);
	str = -str;
	m_str.Format(_T("%lg"), str);
	SetDlgItemText(IDC_EDIT_SHOW, m_str);
}


void CCounterDlg::SaveFirstValue()
{
	m_Num1 = atof(m_str);
	m_str.Format(_T("%lg"), m_Num1);
}


void CCounterDlg::SaveSecondValue()
{
	if (m_str=="")
	{
		m_str = "";
	}
	else
	{
		m_Num3 = atof(m_str);
		m_str.Format(_T("%lg"), m_Num3);
	}
}


void CCounterDlg::OnBnClickedButadd()
{
	// TODO:  在此添加控件通知处理程序代码
	m_str1 += m_str;
	if (m_Num1 == 0)
	{
		SaveFirstValue();
	}
	else
	{
		SaveSecondValue();
	}//在firstvalue和secondvalue中进行计算。
	if (m_str=="")
	{

	}
	else
	{
		Equal();
		
	}

	m_str2 = m_str1 + _T("+");
	if (m_str != "")
	{
		m_str1 += _T("+");
		mFlag = FLAG_JIA;
	}
	else	if (m_str1.GetLength()!= m_str2.GetLength())
	{
		m_str1 = m_str1.Left(m_str1.GetLength() - 1);
		m_str1 += _T("+");
		m_str2 = m_str1;
	}
	SetDlgItemText(IDC_EDIT_SHOW1, m_str1);
	m_str.Format(_T("%lg"), m_Result);
	m_str = "";
	
}


void CCounterDlg::OnBnClickedButdel()
{
	// TODO:  在此添加控件通知处理程序代码
	m_str1 += m_str;
	if (m_Num1 == 0)
	{
		SaveFirstValue();
	}
	else
	{
		SaveSecondValue();
	}//在firstvalue和secondvalue中进行计算。
	if (m_str == "")
	{

	}
	else
	{
		Equal();
	}
	m_str2 = m_str1 + _T("-");
	if (m_str != "")
	{
		m_str1 += _T("-");
		mFlag = FLAG_JIAN;

	}
	else	if (m_str1.GetLength() != m_str2.GetLength())
	{
		m_str1 = m_str1.Left(m_str1.GetLength() - 1);
		m_str1 += _T("-");
		m_str2 = m_str1;
	}
	SetDlgItemText(IDC_EDIT_SHOW1, m_str1);
	m_str = "";
}


void CCounterDlg::OnBnClickedButcheng()
{
	// TODO:  在此添加控件通知处理程序代码
	m_str1 += m_str;
	if (m_Num1 == 0)
	{
		SaveFirstValue();
	}
	else
	{
		SaveSecondValue();
	}//在firstvalue和secondvalue中进行计算。
	if (m_str == "")
	{

	}
	else
	{
		Equal();
	}
	m_str2 = m_str1 + _T("×");
	if (m_str != "")
	{
		m_str1 += _T("×");
		mFlag = FLAG_CHENG;

	}
	else	if (m_str1.GetLength() != m_str2.GetLength())
	{
		m_str1 = m_str1.Left(m_str1.GetLength() - 1);
		m_str1 += _T("×");
		m_str2 = m_str1;
	}
	SetDlgItemText(IDC_EDIT_SHOW1, m_str1);
	m_str = "";
}


void CCounterDlg::OnBnClickedButchu()
{
	// TODO:  在此添加控件通知处理程序代码
	m_str1 += m_str;
	if (m_Num1 == 0)
	{
		SaveFirstValue();
	}
	else
	{
		SaveSecondValue();
	}//在firstvalue和secondvalue中进行计算。
	if (m_str == "")
	{

	}
	else
	{
		Equal();
	}
	m_str2 = m_str1 + _T("÷");
	if (m_str != "")
	{
		m_str1 += _T("÷");
		mFlag = FLAG_CHU;

	}
	else	if (m_str1.GetLength() != m_str2.GetLength())
	{
		
		m_str1 = m_str1.Left(m_str1.GetLength() - 1);
		m_str1 += _T("÷");
		m_str2 = m_str1;
	}
	SetDlgItemText(IDC_EDIT_SHOW1, m_str1);
	m_str = "";
}



void CCounterDlg::OnBnClickedButback()
{
	// TODO:  在此添加控件通知处理程序代码
	if (m_str!="")
	{
		m_str=m_str.Left(m_str.GetLength() - 1);
		SetDlgItemText(IDC_EDIT_SHOW, m_str);
	}
	else
	{
		CString Str;
		Str = m_str+_T("0");
		SetDlgItemText(IDC_EDIT_SHOW, Str);
	}
}


void CCounterDlg::Clear()
{
	CString Str;

	m_str = "";			
	m_str1 = "";		
	m_str2 = "";		
	m_Num1 = 0;			
	m_Num2 = 0;			
	m_Num3 = 0;			
	m_Result = 0;
	Str.Format(_T("%lg"), m_Num1);
	SetDlgItemText(IDC_EDIT_SHOW, Str);
	SetDlgItemText(IDC_EDIT_SHOW1, m_str1);
}


void CCounterDlg::OnBnClickedButclear()
{
	// TODO:  在此添加控件通知处理程序代码
	Clear();
}


void CCounterDlg::OnBnClickedButclear1()
{
	CString  str;

	str = "0";
	m_str = "";
	SetDlgItemText(IDC_EDIT_SHOW, str);
	// TODO:  在此添加控件通知处理程序代码
}


void CCounterDlg::OnBnClickedButsin()
{
	// TODO:  在此添加控件通知处理程序代码
	CString Str;
	CString Str1;
	double Num;

	GetDlgItemText(IDC_EDIT_SHOW, m_str);
	Str1 = m_str;
	Num=atof(m_str);
	Num = sin(Num);
	m_str.Format(_T("%.5f"), Num);
	SaveSecondValue();
	Str = m_str;
	SetDlgItemText(IDC_EDIT_SHOW, Str);
	m_str1 += _T("sin(")+Str1+_T(") ");
	m_str = "";
	SetDlgItemText(IDC_EDIT_SHOW1,m_str1);
}


void CCounterDlg::OnBnClickedButcos()
{
	// TODO:  在此添加控件通知处理程序代码
	CString Str;
	CString Str1;
	double Num;

	GetDlgItemText(IDC_EDIT_SHOW, m_str);
	Str1 = m_str;
	Num = atof(m_str);
	Num = cos(Num);
	m_str.Format(_T("%.5f"), Num);
	SaveSecondValue();
	Str = m_str;
	SetDlgItemText(IDC_EDIT_SHOW, Str);
	m_str1 += _T("cos(") + Str1 + _T(") ");
	m_str = "";
	SetDlgItemText(IDC_EDIT_SHOW1, m_str1);
}


void CCounterDlg::OnBnClickedButtan()
{
	// TODO:  在此添加控件通知处理程序代码
	CString Str;
	CString Str1;
	double Num;

	GetDlgItemText(IDC_EDIT_SHOW, m_str);
	Str1 = m_str;
	Num = atof(m_str);
	Num = tan(Num);
	m_str.Format(_T("%.5f"), Num);
	SaveSecondValue();
	Str = m_str;
	SetDlgItemText(IDC_EDIT_SHOW, Str);
	m_str1 += _T("tan(") + Str1 + _T(") ");
	m_str = "";
	SetDlgItemText(IDC_EDIT_SHOW1, m_str1);
}


void CCounterDlg::OnBnClickedButpf()
{
	// TODO:  在此添加控件通知处理程序代码
	CString Str;
	CString Str1;
	double Num;
	double Num1 = 0;

	GetDlgItemText(IDC_EDIT_SHOW, m_str);
	Str1 = m_str;
	Num = atof(m_str);
	Num = Num*Num;
	m_str.Format(_T("%.5f"), Num);
	SaveSecondValue();
	Str = m_str;
	SetDlgItemText(IDC_EDIT_SHOW, Str);
	m_str1 += _T("sqr(") + Str1 + _T(") ");
	m_str = "";
	SetDlgItemText(IDC_EDIT_SHOW1, m_str1);

}


void CCounterDlg::OnEnChangeEditShow()
{
	// TODO:  如果该控件是 RICHEDIT 控件,它将不
	// 发送此通知,除非重写 CDialogEx::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
}


void CCounterDlg::OnEnChangeEditShow1()
{
	// TODO:  如果该控件是 RICHEDIT 控件,它将不
	// 发送此通知,除非重写 CDialogEx::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
}


void CCounterDlg::OnBnClickedButequal()
{	
	CString Str;
	CString	Str1;
	CString Str2;
	double NUM;

	SaveSecondValue();
	m_str1 += m_str;
	m_str1 += _T("=");//加\t 空格
	Equal();
	GetDlgItemText(IDC_EDIT_SHOW, Str);
	
	m_str1 += Str;
	Str1 = m_str1;
	m_str1 = "";
	NUM = atof(Str);
	m_str.Format(_T("%lg"), NUM);
	SaveFirstValue();
	Str2 = m_str;
	Clear();
	m_str = Str2;
	SetDlgItemText(IDC_EDIT_SHOW, Str2);
	SetDlgItemText(IDC_EDIT_SHOW1, Str1);
	// TODO:  在此添加控件通知处理程序代码
}


void CCounterDlg::Equal()
{
	CString Str;
	switch (mFlag)
	{
	case FLAG_JIA:
		m_Result = m_Num1 + m_Num3;
		m_Num1 = m_Result;
		Str.Format(_T("%lg"), m_Result);
		SetDlgItemText(IDC_EDIT_SHOW, Str);
		break;
	case FLAG_JIAN:
		m_Result = m_Num1 - m_Num3;
		m_Num1 = m_Result;
		Str.Format(_T("%lg"), m_Result);
		SetDlgItemText(IDC_EDIT_SHOW, Str);
		break;
	case FLAG_CHENG:
		m_Result = m_Num1 * m_Num3;
		m_Num1 = m_Result;
		Str.Format(_T("%lg"), m_Result);
		SetDlgItemText(IDC_EDIT_SHOW, Str);
		break;
	case FLAG_CHU:
		m_Result = m_Num1 / m_Num3;
		m_Num1 = m_Result;
		Str.Format(_T("%lg"), m_Result);
		SetDlgItemText(IDC_EDIT_SHOW, Str);
		break;
	}
}

原版本是有sin,cos,tan,平方的,也在代码里面,bug但是没有让他们显示出来,各位大佬可以交流交流。

后续有人想了解具体实现方法和想法可以留言,互相交流。

主要是以学习为目的发这次文章

  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值