1.首先做计算器界面类,界面上要用0-9, +,-,*,/,=等(复杂点还可以做的和XP一样的科学计算器)
2.添加计算逻辑,每个按建点下后,在输出栏的显示
我这里有源代码,你如果要请提供邮箱
附部分核心代码:
1.首先做计算器界面类,界面上要用0-9, +,-,*,/,=等(复杂点还可以做的和XP一样的科学计算器)
2.添加计算逻辑,每个按建点下后,在输出栏的显示
我这里有源代码,你如果要请提供邮箱
附部分核心代码:
void CCalDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCalDlg)
DDX_Control(pDX, IDC_BUTTON_9, m_Button9);
DDX_Control(pDX, IDC_BUTTON_8, m_Button8);
DDX_Control(pDX, IDC_BUTTON_7, m_Button7);
DDX_Control(pDX, IDC_BUTTON_6, m_Button6);
DDX_Control(pDX, IDC_BUTTON_5, m_Button5);
DDX_Control(pDX, IDC_BUTTON_4, m_Button4);
DDX_Control(pDX, IDC_BUTTON_3, m_Button3);
DDX_Control(pDX, IDC_BUTTON_27, m_ButtonLog);
DDX_Control(pDX, IDC_BUTTON_26, m_ButtonLn);
DDX_Control(pDX, IDC_BUTTON_25, m_ButtonExp);
DDX_Control(pDX, IDC_BUTTON_24, m_ButtonPow);
DDX_Control(pDX, IDC_BUTTON_23, m_ButtonCub);
DDX_Control(pDX, IDC_BUTTON_22, m_ButtonSqu);
DDX_Control(pDX, IDC_BUTTON_21, m_ButtonTan);
DDX_Control(pDX, IDC_BUTTON_20, m_ButtonCos);
DDX_Control(pDX, IDC_BUTTON_2, m_Button2);
DDX_Control(pDX, IDC_BUTTON_19, m_ButtonSin);
DDX_Control(pDX, IDC_BUTTON_18, m_ButtonReverse);
DDX_Control(pDX, IDC_BUTTON_17, m_ButtonSqrt);
DDX_Control(pDX, IDC_BUTTON_16, m_ButtonClear);
DDX_Control(pDX, IDC_BUTTON_15, m_ButtonDiv);
DDX_Control(pDX, IDC_BUTTON_14, m_ButtonMul);
DDX_Control(pDX, IDC_BUTTON_13, m_ButtonSub);
DDX_Control(pDX, IDC_BUTTON_12, m_ButtonAdd);
DDX_Control(pDX, IDC_BUTTON_11, m_ButtonEqu);
DDX_Control(pDX, IDC_BUTTON_10, m_ButtonPoint);
DDX_Control(pDX, IDC_BUTTON_1, m_Button1);
DDX_Control(pDX, IDC_BUTTON_0, m_Button0);
DDX_Control(pDX, IDC_EDIT1, m_DspEdit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCalDlg, CDialog)
//{{AFX_MSG_MAP(CCalDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_0, OnButton0)
ON_BN_CLICKED(IDC_BUTTON_1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON_11, OnButtonEqu)
ON_BN_CLICKED(IDC_BUTTON_12, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_10, OnButtonPoint)
ON_BN_CLICKED(IDC_BUTTON_13, OnButtonSub)
ON_BN_CLICKED(IDC_BUTTON_14, OnButtonMul)
ON_BN_CLICKED(IDC_BUTTON_15, OnButtonDiv)
ON_BN_CLICKED(IDC_BUTTON_16, OnButtonClear)
ON_BN_CLICKED(IDC_BUTTON_17, OnButtonSqrt)
ON_BN_CLICKED(IDC_BUTTON_18, OnButtonReverse)
ON_BN_CLICKED(IDC_BUTTON_19, OnButtonSin)
ON_BN_CLICKED(IDC_BUTTON_2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON_20, OnButtonCos)
ON_BN_CLICKED(IDC_BUTTON_21, OnButtonTan)
ON_BN_CLICKED(IDC_BUTTON_22, OnButtonSqu)
ON_BN_CLICKED(IDC_BUTTON_23, OnButtonCub)
ON_BN_CLICKED(IDC_BUTTON_24, OnButtonPow)
ON_BN_CLICKED(IDC_BUTTON_25, OnButtonExp)
ON_BN_CLICKED(IDC_BUTTON_26, OnButtonLn)
ON_BN_CLICKED(IDC_BUTTON_27, OnButtonLog)
ON_BN_CLICKED(IDC_BUTTON_3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON_4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON_5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON_6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON_7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON_8, OnButton8)
ON_BN_CLICKED(IDC_BUTTON_9, OnButton9)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CCalDlg::OnButton0()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
m_StrBegin=m_StrBegin+"0";
m_DspEdit.OnDisplay(m_StrBegin);
}
else
{
m_StrEnd=m_StrEnd+"0";
m_IsCheckPoint=0;
m_DspEdit.OnDisplay(m_StrEnd);
}
}
void CCalDlg::OnButton1()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
m_StrBegin=m_StrBegin+"1";
m_DspEdit.OnDisplay(m_StrBegin);
}
else
{
m_StrEnd=m_StrEnd+"1";
m_IsCheckPoint=0;
m_DspEdit.OnDisplay(m_StrEnd);
}
}
void CCalDlg::OnButtonEqu()
{
// TODO: Add your control notification handler code here
Result();
}
void CCalDlg::OnButtonAdd()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=1;
m_Mark=1;
}
void CCalDlg::OnButtonPoint()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
if(m_IsCheckPoint!=1&&m_StrBegin!="")
{
m_StrBegin=m_StrBegin+".";
m_IsCheckPoint=1;
}
}
else
{
if(m_IsCheckPoint!=1&&m_StrBegin!="")
{
m_StrEnd=m_StrEnd+".";
m_IsCheckPoint=1;
}
}
}
void CCalDlg::OnButtonSub()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=2;
m_Mark=1;
}
void CCalDlg::OnButtonMul()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=3;
m_Mark=1;
}
void CCalDlg::OnButtonDiv()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=4;
m_Mark=1;
}
void CCalDlg::OnButtonClear()
{
// TODO: Add your control notification handler code here
m_IsCheckPoint=0; //マ﨤ミ。ハオ羃エマツオトア・ヌ
m_StrBegin="";
m_StrEnd="";
m_Mark=0;
m_begin=0.0;
m_end=0.0;
m_bit=0;
m_DspEdit.OnDisplay("0.");
}
void CCalDlg::OnButtonSqrt()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=5;
m_Mark=1;
}
void CCalDlg::OnButtonReverse()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=6;
m_Mark=1;
}
void CCalDlg::OnButtonSin()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=8;
m_Mark=1;
}
void CCalDlg::OnButton2()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
m_StrBegin=m_StrBegin+"2";
m_DspEdit.OnDisplay(m_StrBegin);
}
else
{
m_StrEnd=m_StrEnd+"2";
m_IsCheckPoint=0;
m_DspEdit.OnDisplay(m_StrEnd);
}
}
void CCalDlg::OnButtonCos()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=9;
m_Mark=1;
}
void CCalDlg::OnButtonTan()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=10;
m_Mark=1;
}
void CCalDlg::OnButtonSqu()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=11;
m_Mark=1;
}
void CCalDlg::OnButtonCub()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=12;
m_Mark=1;
}
void CCalDlg::OnButtonPow()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=13;
m_Mark=1;
}
void CCalDlg::OnButtonExp()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=14;
m_Mark=1;
}
void CCalDlg::OnButtonLn()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=15;
m_Mark=1;
}
void CCalDlg::OnButtonLog()
{
// TODO: Add your control notification handler code here
m_begin=atof(m_StrBegin);
m_bit=16;
m_Mark=1;
}
void CCalDlg::OnButton3()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
m_StrBegin=m_StrBegin+"3";
m_DspEdit.OnDisplay(m_StrBegin);
}
else
{
m_StrEnd=m_StrEnd+"3";
m_IsCheckPoint=0;
m_DspEdit.OnDisplay(m_StrEnd);
}
}
void CCalDlg::OnButton4()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
m_StrBegin=m_StrBegin+"4";
m_DspEdit.OnDisplay(m_StrBegin);
}
else
{
m_StrEnd=m_StrEnd+"4";
m_IsCheckPoint=0;
m_DspEdit.OnDisplay(m_StrEnd);
}
}
void CCalDlg::OnButton5()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
m_StrBegin=m_StrBegin+"5";
m_DspEdit.OnDisplay(m_StrBegin);
}
else
{
m_StrEnd=m_StrEnd+"5";
m_IsCheckPoint=0;
m_DspEdit.OnDisplay(m_StrEnd);
}
}
void CCalDlg::OnButton6()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
m_StrBegin=m_StrBegin+"6";
m_DspEdit.OnDisplay(m_StrBegin);
}
else
{
m_StrEnd=m_StrEnd+"6";
m_IsCheckPoint=0;
m_DspEdit.OnDisplay(m_StrEnd);
}
}
void CCalDlg::OnButton7()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
m_StrBegin=m_StrBegin+"7";
m_DspEdit.OnDisplay(m_StrBegin);
}
else
{
m_StrEnd=m_StrEnd+"7";
m_IsCheckPoint=0;
m_DspEdit.OnDisplay(m_StrEnd);
}
}
void CCalDlg::OnButton8()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
m_StrBegin=m_StrBegin+"8";
m_DspEdit.OnDisplay(m_StrBegin);
}
else
{
m_StrEnd=m_StrEnd+"8";
m_IsCheckPoint=0;
m_DspEdit.OnDisplay(m_StrEnd);
}
}
void CCalDlg::OnButton9()
{
// TODO: Add your control notification handler code here
if(m_Mark==0)
{
m_StrBegin=m_StrBegin+"9";
m_DspEdit.OnDisplay(m_StrBegin);
}
else
{
m_StrEnd=m_StrEnd+"9";
m_IsCheckPoint=0;
m_DspEdit.OnDisplay(m_StrEnd);
}
}
void CCalDlg::Result()
{
m_end=atof(m_StrEnd); //ームハ菠・センラェササホェク。オ飜
switch(m_bit)
{
case 1:
m_end+=m_begin;
break;
case 2:
m_end=m_begin-m_end;
break;
case 3:
m_end=m_begin*m_end;
break;
case 4:
m_end=m_begin/m_end;
break;
case 5:
if(m_end<0)
{
m_DspEdit.OnDisplay("コッハハ菠・゙ミァ!");
break;
}
m_end=sqrt(m_end);
break;
case 6:
if(m_end==0)
{ m_DspEdit.OnDisplay("キヨトクハ菠・゙ミァ!");
break;
}
m_end=1.0/m_end;
break;
case 8:
m_end=sin(m_end);
break;
case 9:
m_end=cos(m_end);
break;
case 10:
m_end=tan(m_end);
break;
case 11:
m_end=m_end*m_end;
break;
case 12:
m_end=m_end*m_end*m_end;
break;
case 13:
m_end=pow(m_begin,m_end);
break;
case 14:
m_end=exp(m_end);
break;
case 15:
if(m_end<=0)
{
m_DspEdit.OnDisplay("コッハハ菠・゙ミァ!");
break;
}
m_end=log(m_end);
break;
case 16:
if(m_end<=0)
{
m_DspEdit.OnDisplay("コッハハ菠・゙ミァ!");
return;
}
m_end=log10(m_end);
break;
}
m_begin=m_end;
m_bit=0;
m_StrEnd="";
gcvt(m_end,15,m_buffer);
m_StrBegin=m_buffer;
m_DspEdit.SetSel(0,-1);
m_DspEdit.ReplaceSel(" ");
m_DspEdit.OnDisplay(m_buffer);
}
温馨提示:内容为网友见解,仅供参考