展开全部
很简单的,包含各种运算符的计算器。
//MyDlg的头文件
// CMyDlg 对话框
#include "afxwin.h"
class CMyDlg : public CDialog
{
DECLARE_DYNAMIC(CMyDlg)
public:
CMyDlg(CWnd* pParent = NULL); // 标准构造函数
virtual ~CMyDlg();
BOOL PreTranslateMessage(MSG* pMsg);
// 对话框数据
enum { IDD = IDD_LOGIN_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedButton1();
public:
void Calc1();//按下数字键
void Calc2();//按下符号键
protected:
char m_sign;//记录按下哪个运算符
int m_numb;//记录按了哪个数字键
bool point;//是否按下小数点
bool equals;//是否按下等号
bool num; //是否按下数字键
bool funs;//是否按下功能键
int nums;//运算小数点之后的值
double number1;//按下运算符之后的数值
double number2;//没按运算符之前的数值
int m_edit;//记录按下的数字键的数值
char c_edit;//记录按下的运算符
CString m_EDIT1;
CString n_EDIT1;
protected:
afx_msg void OnClose();
public:
afx_msg void OnBnClickedButton17();
afx_msg void OnBnClickedButton18();
afx_msg void OnBnClickedButton21();
afx_msg void OnBnClickedButton2();
afx_msg void OnBnClickedButton3();
afx_msg void OnBnClickedButton4();
afx_msg void OnBnClickedButton5();
afx_msg void OnBnClickedButton6();
afx_msg void OnBnClickedButton7();
afx_msg void OnBnClickedButton8();
afx_msg void OnBnClickedButton9();
afx_msg void OnBnClickedButton10();
afx_msg void OnBnClickedButton12();
afx_msg void OnBnClickedButton13();
afx_msg void OnBnClickedButton14();
afx_msg void OnBnClickedButton15();
afx_msg void OnBnClickedButton19();
afx_msg void OnBnClickedButton11();
afx_msg void OnBnClickedButton16();
afx_msg void OnBnClickedButton20();
afx_msg void OnBnClickedButton22();
afx_msg void OnBnClickedButton25();
afx_msg void OnBnClickedButton24();
afx_msg void OnBnClickedButton23();
afx_msg void OnBnClickedButton26();
CEdit m_EDIT;
// afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
};
#pragma once
// MyDlg.cpp : 实现文件
#include "stdafx.h"
#include "MyDlg.h"
#include "math.h"
// CMyDlg 对话框
IMPLEMENT_DYNAMIC(CMyDlg, CDialog)
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
number1 = 0;
number2 = 0;
nums =-1;
num = false;
point = false;
equals = false;
funs = false;
m_sign = '=';
}
CMyDlg::~CMyDlg()
{
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
/*DDX_Control(pDX, IDC_USERNAME, m_EDIT);*/
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
/*ON_BN_CLICKED(IDC_BUTTON1, &CMyDlg::OnBnClickedButton1)*/
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON17, &CMyDlg::OnBnClickedButton17)
ON_BN_CLICKED(IDC_BUTTON18, &CMyDlg::OnBnClickedButton18)
ON_BN_CLICKED(IDC_BUTTON21, &CMyDlg::OnBnClickedButton21)
ON_BN_CLICKED(IDC_BUTTON2, &CMyDlg::OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON3, &CMyDlg::OnBnClickedButton3)
ON_BN_CLICKED(IDC_BUTTON4, &CMyDlg::OnBnClickedButton4)
ON_BN_CLICKED(IDC_BUTTON5, &CMyDlg::OnBnClickedButton5)
ON_BN_CLICKED(IDC_BUTTON6, &CMyDlg::OnBnClickedButton6)
ON_BN_CLICKED(IDC_BUTTON7, &CMyDlg::OnBnClickedButton7)
ON_BN_CLICKED(IDC_BUTTON8, &CMyDlg::OnBnClickedButton8)
ON_BN_CLICKED(IDC_BUTTON9, &CMyDlg::OnBnClickedButton9)
ON_BN_CLICKED(IDC_BUTTON10, &CMyDlg::OnBnClickedButton10)
ON_BN_CLICKED(IDC_BUTTON12, &CMyDlg::OnBnClickedButton12)
ON_BN_CLICKED(IDC_BUTTON13, &CMyDlg::OnBnClickedButton13)
ON_BN_CLICKED(IDC_BUTTON14, &CMyDlg::OnBnClickedButton14)
ON_BN_CLICKED(IDC_BUTTON15, &CMyDlg::OnBnClickedButton15)
ON_BN_CLICKED(IDC_BUTTON19, &CMyDlg::OnBnClickedButton19)
ON_BN_CLICKED(IDC_BUTTON11, &CMyDlg::OnBnClickedButton11)
ON_BN_CLICKED(IDC_BUTTON16, &CMyDlg::OnBnClickedButton16)
ON_BN_CLICKED(IDC_BUTTON20, &CMyDlg::OnBnClickedButton20)
ON_BN_CLICKED(IDC_BUTTON22, &CMyDlg::OnBnClickedButton22)
ON_BN_CLICKED(IDC_BUTTON25, &CMyDlg::OnBnClickedButton25)
ON_BN_CLICKED(IDC_BUTTON24, &CMyDlg::OnBnClickedButton24)
ON_BN_CLICKED(IDC_BUTTON23, &CMyDlg::OnBnClickedButton23)
ON_BN_CLICKED(IDC_BUTTON26, &CMyDlg::OnBnClickedButton26)
// ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
// CMyDlg 消息处理程序
// void CMyDlg::OnBnClickedButton1()
// {
// // TODO: 在此添加控件通知处理程序代码
// }
void CMyDlg::OnBnClickedButton17()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = sqrt(number1);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = sqrt(number2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton18()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
if (number1!=0)
{
number1 = 1/number1;
m_EDIT1.Format("%lg",number1);
}
else
{
m_EDIT1 = "除数不能为0";
}
}
else
{
if (number2!=0)
{
number2 = 1/number2;
m_EDIT1.Format("%lg",number2);
}
else
{
m_EDIT1 = "除数不能为0";
}
}
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton21()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 1;
Calc1();
}
void CMyDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 2;
Calc1();
}
void CMyDlg::OnBnClickedButton3()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 3;
Calc1();
}
void CMyDlg::OnBnClickedButton4()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 4;
Calc1();
}
void CMyDlg::OnBnClickedButton5()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 5;
Calc1();
}
void CMyDlg::OnBnClickedButton6()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 6;
Calc1();
}
void CMyDlg::OnBnClickedButton7()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 7;
Calc1();
}
void CMyDlg::OnBnClickedButton8()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 8;
Calc1();
}
void CMyDlg::OnBnClickedButton9()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 9;
Calc1();
}
void CMyDlg::OnBnClickedButton10()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 0;
Calc1();
}
void CMyDlg::OnBnClickedButton12()
{
// TODO: 在此添加控件通知处理程序代码
Calc2();
m_sign = '+';
}
void CMyDlg::OnBnClickedButton13()
{
// TODO: 在此添加控件通知处理程序代码
Calc2();
m_sign = '-';
}
void CMyDlg::OnBnClickedButton14()
{
// TODO: 在此添加控件通知处理程序代码
Calc2();
m_sign = '*';
}
void CMyDlg::OnBnClickedButton15()
{
// TODO: 在此添加控件通知处理程序代码
Calc2();
m_sign = '/';
}
void CMyDlg::OnBnClickedButton19()
{
// TODO: 在此添加控件通知处理程序代码
number1 = 0;
number2 = 0;
nums =-1;
num = false;
point = false;
equals = false;
funs = false;
m_sign = '=';
m_EDIT1.Format("%lg",number1);
SetDlgItemText(IDC_EDIT1,m_EDIT1);
}
void CMyDlg::OnBnClickedButton11()
{
// TODO: 在此添加控件通知处理程序代码
Calc2();
m_sign = '=';
equals = true;
}
void CMyDlg::OnBnClickedButton16()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
if (point == true)
{
m_EDIT1.Format("%lg",number1);
}
else
{
m_EDIT1.Format("%lg",number1);
m_EDIT1 += ".";
}
}
else
{
if (point == true)
{
m_EDIT1.Format("%lg",number2);
}
else
{
m_EDIT1.Format("%lg",number2);
m_EDIT1 += ".";
}
}
point = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::Calc1()//点击数字键
{
switch(m_numb)
{
case 0:
m_edit = 0;
break;
case 1:
m_edit = 1;
break;
case 2:
m_edit = 2;
break;
case 3:
m_edit = 3;
break;
case 4:
m_edit = 4;
break;
case 5:
m_edit = 5;
break;
case 6:
m_edit = 6;
break;
case 7:
m_edit = 7;
break;
case 8:
m_edit = 8;
break;
case 9:
m_edit = 9;
break;
}
if (equals)
{
equals = false;
num = false;
}
if (point)
{
number2 = number2+m_edit*pow((double)10,(double)(nums--));
if (m_edit == 0)
{
if (nums == -2)
{
m_EDIT1.Format("%lg",number2);
m_EDIT1 += ".0";
}
else
{
m_EDIT1.Format("%lg",number2);
m_EDIT1 += "0";
}
}
else
m_EDIT1.Format("%lg",number2);
}
else
{
number2 = number2 * 10 + m_edit;
m_EDIT1.Format("%lg",number2);
}
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::Calc2()//点击运算符
{
if (!equals)
{
if (num)//按下运算符之后,接着是否按下了数字键
{
switch (m_sign)
{
case '+':
number1 = number1+number2;
break;
case '-':
number1 = number1-number2;
break;
case '*':
number1 = number1*number2;
break;
case '/':
if (number2 != 0)
{
number1 = number1/number2;
}
break;
}
}
else
{
number1 = number2;
num = true;
}
}
else
{
equals = false;
}
if (m_sign == '/'&& number2 == 0)
m_EDIT1 = "除数不能为零";
else
m_EDIT1.Format("%lg",number1);
number2 = 0;
point = false;
nums = -1;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton20()//退格键
{
// TODO: 在此添加控件通知处理程序代码
if (!(equals||funs))
{
m_EDIT1.Format("%lg",number2);
int n = m_EDIT1.GetLength()-1;
CString c1 = m_EDIT1.Left(n);
if (n)
SetDlgItemText(IDC_EDIT1,c1);
else
SetDlgItemText(IDC_EDIT1,"0");
number2 = atof(c1);
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton22()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = sin(number1);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = sin(number2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton25()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = exp(number1);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = exp(number2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton24()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = log(number1);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = log(number2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton23()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = cos(number1);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = cos(number2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton26()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = pow(number1,2);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = pow(number2,2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnClose()
{
if ( MessageBox(_T("是否退出程序?"),_T("提示"),MB_YESNO|MB_ICONQUESTION) == IDYES )
{
CDialog::OnClose();
}
}
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam == VK_ESCAPE)
{
return true;
}
if(pMsg->wParam == VK_RETURN)
{
return true;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
//MyDlg的头文件
// CMyDlg 对话框
#include "afxwin.h"
class CMyDlg : public CDialog
{
DECLARE_DYNAMIC(CMyDlg)
public:
CMyDlg(CWnd* pParent = NULL); // 标准构造函数
virtual ~CMyDlg();
BOOL PreTranslateMessage(MSG* pMsg);
// 对话框数据
enum { IDD = IDD_LOGIN_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedButton1();
public:
void Calc1();//按下数字键
void Calc2();//按下符号键
protected:
char m_sign;//记录按下哪个运算符
int m_numb;//记录按了哪个数字键
bool point;//是否按下小数点
bool equals;//是否按下等号
bool num; //是否按下数字键
bool funs;//是否按下功能键
int nums;//运算小数点之后的值
double number1;//按下运算符之后的数值
double number2;//没按运算符之前的数值
int m_edit;//记录按下的数字键的数值
char c_edit;//记录按下的运算符
CString m_EDIT1;
CString n_EDIT1;
protected:
afx_msg void OnClose();
public:
afx_msg void OnBnClickedButton17();
afx_msg void OnBnClickedButton18();
afx_msg void OnBnClickedButton21();
afx_msg void OnBnClickedButton2();
afx_msg void OnBnClickedButton3();
afx_msg void OnBnClickedButton4();
afx_msg void OnBnClickedButton5();
afx_msg void OnBnClickedButton6();
afx_msg void OnBnClickedButton7();
afx_msg void OnBnClickedButton8();
afx_msg void OnBnClickedButton9();
afx_msg void OnBnClickedButton10();
afx_msg void OnBnClickedButton12();
afx_msg void OnBnClickedButton13();
afx_msg void OnBnClickedButton14();
afx_msg void OnBnClickedButton15();
afx_msg void OnBnClickedButton19();
afx_msg void OnBnClickedButton11();
afx_msg void OnBnClickedButton16();
afx_msg void OnBnClickedButton20();
afx_msg void OnBnClickedButton22();
afx_msg void OnBnClickedButton25();
afx_msg void OnBnClickedButton24();
afx_msg void OnBnClickedButton23();
afx_msg void OnBnClickedButton26();
CEdit m_EDIT;
// afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
};
#pragma once
// MyDlg.cpp : 实现文件
#include "stdafx.h"
#include "MyDlg.h"
#include "math.h"
// CMyDlg 对话框
IMPLEMENT_DYNAMIC(CMyDlg, CDialog)
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
number1 = 0;
number2 = 0;
nums =-1;
num = false;
point = false;
equals = false;
funs = false;
m_sign = '=';
}
CMyDlg::~CMyDlg()
{
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
/*DDX_Control(pDX, IDC_USERNAME, m_EDIT);*/
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
/*ON_BN_CLICKED(IDC_BUTTON1, &CMyDlg::OnBnClickedButton1)*/
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON17, &CMyDlg::OnBnClickedButton17)
ON_BN_CLICKED(IDC_BUTTON18, &CMyDlg::OnBnClickedButton18)
ON_BN_CLICKED(IDC_BUTTON21, &CMyDlg::OnBnClickedButton21)
ON_BN_CLICKED(IDC_BUTTON2, &CMyDlg::OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON3, &CMyDlg::OnBnClickedButton3)
ON_BN_CLICKED(IDC_BUTTON4, &CMyDlg::OnBnClickedButton4)
ON_BN_CLICKED(IDC_BUTTON5, &CMyDlg::OnBnClickedButton5)
ON_BN_CLICKED(IDC_BUTTON6, &CMyDlg::OnBnClickedButton6)
ON_BN_CLICKED(IDC_BUTTON7, &CMyDlg::OnBnClickedButton7)
ON_BN_CLICKED(IDC_BUTTON8, &CMyDlg::OnBnClickedButton8)
ON_BN_CLICKED(IDC_BUTTON9, &CMyDlg::OnBnClickedButton9)
ON_BN_CLICKED(IDC_BUTTON10, &CMyDlg::OnBnClickedButton10)
ON_BN_CLICKED(IDC_BUTTON12, &CMyDlg::OnBnClickedButton12)
ON_BN_CLICKED(IDC_BUTTON13, &CMyDlg::OnBnClickedButton13)
ON_BN_CLICKED(IDC_BUTTON14, &CMyDlg::OnBnClickedButton14)
ON_BN_CLICKED(IDC_BUTTON15, &CMyDlg::OnBnClickedButton15)
ON_BN_CLICKED(IDC_BUTTON19, &CMyDlg::OnBnClickedButton19)
ON_BN_CLICKED(IDC_BUTTON11, &CMyDlg::OnBnClickedButton11)
ON_BN_CLICKED(IDC_BUTTON16, &CMyDlg::OnBnClickedButton16)
ON_BN_CLICKED(IDC_BUTTON20, &CMyDlg::OnBnClickedButton20)
ON_BN_CLICKED(IDC_BUTTON22, &CMyDlg::OnBnClickedButton22)
ON_BN_CLICKED(IDC_BUTTON25, &CMyDlg::OnBnClickedButton25)
ON_BN_CLICKED(IDC_BUTTON24, &CMyDlg::OnBnClickedButton24)
ON_BN_CLICKED(IDC_BUTTON23, &CMyDlg::OnBnClickedButton23)
ON_BN_CLICKED(IDC_BUTTON26, &CMyDlg::OnBnClickedButton26)
// ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
// CMyDlg 消息处理程序
// void CMyDlg::OnBnClickedButton1()
// {
// // TODO: 在此添加控件通知处理程序代码
// }
void CMyDlg::OnBnClickedButton17()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = sqrt(number1);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = sqrt(number2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton18()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
if (number1!=0)
{
number1 = 1/number1;
m_EDIT1.Format("%lg",number1);
}
else
{
m_EDIT1 = "除数不能为0";
}
}
else
{
if (number2!=0)
{
number2 = 1/number2;
m_EDIT1.Format("%lg",number2);
}
else
{
m_EDIT1 = "除数不能为0";
}
}
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton21()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 1;
Calc1();
}
void CMyDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 2;
Calc1();
}
void CMyDlg::OnBnClickedButton3()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 3;
Calc1();
}
void CMyDlg::OnBnClickedButton4()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 4;
Calc1();
}
void CMyDlg::OnBnClickedButton5()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 5;
Calc1();
}
void CMyDlg::OnBnClickedButton6()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 6;
Calc1();
}
void CMyDlg::OnBnClickedButton7()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 7;
Calc1();
}
void CMyDlg::OnBnClickedButton8()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 8;
Calc1();
}
void CMyDlg::OnBnClickedButton9()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 9;
Calc1();
}
void CMyDlg::OnBnClickedButton10()
{
// TODO: 在此添加控件通知处理程序代码
m_numb = 0;
Calc1();
}
void CMyDlg::OnBnClickedButton12()
{
// TODO: 在此添加控件通知处理程序代码
Calc2();
m_sign = '+';
}
void CMyDlg::OnBnClickedButton13()
{
// TODO: 在此添加控件通知处理程序代码
Calc2();
m_sign = '-';
}
void CMyDlg::OnBnClickedButton14()
{
// TODO: 在此添加控件通知处理程序代码
Calc2();
m_sign = '*';
}
void CMyDlg::OnBnClickedButton15()
{
// TODO: 在此添加控件通知处理程序代码
Calc2();
m_sign = '/';
}
void CMyDlg::OnBnClickedButton19()
{
// TODO: 在此添加控件通知处理程序代码
number1 = 0;
number2 = 0;
nums =-1;
num = false;
point = false;
equals = false;
funs = false;
m_sign = '=';
m_EDIT1.Format("%lg",number1);
SetDlgItemText(IDC_EDIT1,m_EDIT1);
}
void CMyDlg::OnBnClickedButton11()
{
// TODO: 在此添加控件通知处理程序代码
Calc2();
m_sign = '=';
equals = true;
}
void CMyDlg::OnBnClickedButton16()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
if (point == true)
{
m_EDIT1.Format("%lg",number1);
}
else
{
m_EDIT1.Format("%lg",number1);
m_EDIT1 += ".";
}
}
else
{
if (point == true)
{
m_EDIT1.Format("%lg",number2);
}
else
{
m_EDIT1.Format("%lg",number2);
m_EDIT1 += ".";
}
}
point = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::Calc1()//点击数字键
{
switch(m_numb)
{
case 0:
m_edit = 0;
break;
case 1:
m_edit = 1;
break;
case 2:
m_edit = 2;
break;
case 3:
m_edit = 3;
break;
case 4:
m_edit = 4;
break;
case 5:
m_edit = 5;
break;
case 6:
m_edit = 6;
break;
case 7:
m_edit = 7;
break;
case 8:
m_edit = 8;
break;
case 9:
m_edit = 9;
break;
}
if (equals)
{
equals = false;
num = false;
}
if (point)
{
number2 = number2+m_edit*pow((double)10,(double)(nums--));
if (m_edit == 0)
{
if (nums == -2)
{
m_EDIT1.Format("%lg",number2);
m_EDIT1 += ".0";
}
else
{
m_EDIT1.Format("%lg",number2);
m_EDIT1 += "0";
}
}
else
m_EDIT1.Format("%lg",number2);
}
else
{
number2 = number2 * 10 + m_edit;
m_EDIT1.Format("%lg",number2);
}
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::Calc2()//点击运算符
{
if (!equals)
{
if (num)//按下运算符之后,接着是否按下了数字键
{
switch (m_sign)
{
case '+':
number1 = number1+number2;
break;
case '-':
number1 = number1-number2;
break;
case '*':
number1 = number1*number2;
break;
case '/':
if (number2 != 0)
{
number1 = number1/number2;
}
break;
}
}
else
{
number1 = number2;
num = true;
}
}
else
{
equals = false;
}
if (m_sign == '/'&& number2 == 0)
m_EDIT1 = "除数不能为零";
else
m_EDIT1.Format("%lg",number1);
number2 = 0;
point = false;
nums = -1;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton20()//退格键
{
// TODO: 在此添加控件通知处理程序代码
if (!(equals||funs))
{
m_EDIT1.Format("%lg",number2);
int n = m_EDIT1.GetLength()-1;
CString c1 = m_EDIT1.Left(n);
if (n)
SetDlgItemText(IDC_EDIT1,c1);
else
SetDlgItemText(IDC_EDIT1,"0");
number2 = atof(c1);
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton22()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = sin(number1);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = sin(number2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton25()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = exp(number1);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = exp(number2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton24()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = log(number1);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = log(number2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton23()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = cos(number1);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = cos(number2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButton26()
{
// TODO: 在此添加控件通知处理程序代码
if (equals)
{
number1 = pow(number1,2);
m_EDIT1.Format("%lg",number1);
}
else
{
number2 = pow(number2,2);
m_EDIT1.Format("%lg",number2);
/*IDC_EDIT1.SetWindowText(m_EDIT1);*/
}
funs = true;
SetDlgItemText(IDC_EDIT1,m_EDIT1);
UpdateData(FALSE);
}
void CMyDlg::OnClose()
{
if ( MessageBox(_T("是否退出程序?"),_T("提示"),MB_YESNO|MB_ICONQUESTION) == IDYES )
{
CDialog::OnClose();
}
}
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam == VK_ESCAPE)
{
return true;
}
if(pMsg->wParam == VK_RETURN)
{
return true;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
展开全部
给你一个网址你就会了,http://www.jizhuomi.com/software/257.html 虽然他是在VS2010上实现的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已发送,请注意查收。Q尾号5921
本人有大量C++源码,有需要再联系!
请采纳。
本人有大量C++源码,有需要再联系!
请采纳。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询