早期作品,很简单的MFC程序...
void CMfc_CounterDlg::OnOK()
{
// TODO: Add extra validation here
}
void CMfc_CounterDlg::OnAdd() //按下了+号键,计算 + 运算
{
// TODO: Add your control notification handler code here
m_isBtnDown=TRUE; //判断+号是否按下
m_countType='+';
OnAmount() ; //计算结果
}
void CMfc_CounterDlg::OnMinus() //按下了-号键,计算 - 运算
{
// TODO: Add your control notification handler code here
m_isBtnDown=TRUE; //判断-号是否按下
m_countType='-';
OnAmount() ; //计算结果
}
void CMfc_CounterDlg::OnChu() //按下了/号键,计算 / 运算
{
// TODO: Add your control notification handler code here
m_isBtnDown=TRUE; //判断/号是否按下
m_countType='/';
OnAmount() ; //计算结果
}
void CMfc_CounterDlg::OnRide() //按下了*号键,计算 * 运算
{
// TODO: Add your control notification handler code here
m_isBtnDown=TRUE; //判断*号是否按下
m_countType='*';
OnAmount() ; //计算结果
}
void CMfc_CounterDlg::OnEight() //按下了“8”
{
OnCount('8'); //是按下那个数字
}
void CMfc_CounterDlg::OnFive() //按下了“5”
{
OnCount('5'); //是按下那个数字
}
void CMfc_CounterDlg::OnFour() //按下了“4”
{
OnCount('4'); //是按下那个数字
}
void CMfc_CounterDlg::OnNine() //按下了“9”
{
OnCount('9'); //是按下那个数字
}
void CMfc_CounterDlg::OnOne() //按下了“1”
{
// TODO: Add your control notification handler code here
OnCount('1'); //是按下那个数字
}
void CMfc_CounterDlg::OnSeven() //按下了“7”
{
// TODO: Add your control notification handler code here
OnCount('7'); //是按下那个数字
}
void CMfc_CounterDlg::OnSix() //按下了“6”
{
// TODO: Add your control notification handler code here
OnCount('6'); //是按下那个数字
}
void CMfc_CounterDlg::OnThree() //按下了“3”
{
// TODO: Add your control notification handler code here
OnCount('3'); //是按下那个数字
}
void CMfc_CounterDlg::OnTwo() //按下了“2”
{
// TODO: Add your control notification handler code here
OnCount('2'); //是按下那个数字
}
void CMfc_CounterDlg::OnZero() //按下了“0”
{
// TODO: Add your control notification handler code here
OnCount('0'); //是按下那个数字
}
void CMfc_CounterDlg::OnAmount() //计算结果
{
// TODO: Add your control notification handler code here
m_isBtnDown=TRUE; //判断=号是否按下
m_secondNum=atof(m_number); //字符串转double
SetDlgItemText(IDC_EDIT1,m_number);
/*
计算结果
*/
if(m_countType=='+')//计算 和
{
m_count.Format("%lf",m_firstNum+m_secondNum);
}
else if(m_countType=='-')//计算 减
{
if(m_firstNum!=0)
{
m_count.Format("%lf",m_firstNum-m_secondNum);
}
else
{m_firstNum=m_secondNum;
m_count.Format("%lf",m_firstNum);
}
}
else if(m_countType=='*') //计算 乘
{
if(m_firstNum==0)
{
m_firstNum=1;
}
m_count.Format("%lf",m_firstNum*m_secondNum);
}
else if(m_countType=='/') //计算 除
{ if(m_firstNum==0)
{
m_firstNum=m_secondNum;
m_secondNum=1;
}
if(m_secondNum!=0)
{
m_count.Format("%lf",m_firstNum/m_secondNum);
}
else
{
m_number="被除数不能为0,重新输入!";
UpdateData(FALSE);
}
}
UpdateData(FALSE);
SetDlgItemText(IDC_EDIT1,m_count);
}
void CMfc_CounterDlg::OnOK()
{
// TODO: Add extra validation here
}
void CMfc_CounterDlg::OnAdd() //按下了+号键,计算 + 运算
{
// TODO: Add your control notification handler code here
m_isBtnDown=TRUE; //判断+号是否按下
m_countType='+';
OnAmount() ; //计算结果
}
void CMfc_CounterDlg::OnMinus() //按下了-号键,计算 - 运算
{
// TODO: Add your control notification handler code here
m_isBtnDown=TRUE; //判断-号是否按下
m_countType='-';
OnAmount() ; //计算结果
}
void CMfc_CounterDlg::OnChu() //按下了/号键,计算 / 运算
{
// TODO: Add your control notification handler code here
m_isBtnDown=TRUE; //判断/号是否按下
m_countType='/';
OnAmount() ; //计算结果
}
void CMfc_CounterDlg::OnRide() //按下了*号键,计算 * 运算
{
// TODO: Add your control notification handler code here
m_isBtnDown=TRUE; //判断*号是否按下
m_countType='*';
OnAmount() ; //计算结果
}
void CMfc_CounterDlg::OnEight() //按下了“8”
{
OnCount('8'); //是按下那个数字
}
void CMfc_CounterDlg::OnFive() //按下了“5”
{
OnCount('5'); //是按下那个数字
}
void CMfc_CounterDlg::OnFour() //按下了“4”
{
OnCount('4'); //是按下那个数字
}
void CMfc_CounterDlg::OnNine() //按下了“9”
{
OnCount('9'); //是按下那个数字
}
void CMfc_CounterDlg::OnOne() //按下了“1”
{
// TODO: Add your control notification handler code here
OnCount('1'); //是按下那个数字
}
void CMfc_CounterDlg::OnSeven() //按下了“7”
{
// TODO: Add your control notification handler code here
OnCount('7'); //是按下那个数字
}
void CMfc_CounterDlg::OnSix() //按下了“6”
{
// TODO: Add your control notification handler code here
OnCount('6'); //是按下那个数字
}
void CMfc_CounterDlg::OnThree() //按下了“3”
{
// TODO: Add your control notification handler code here
OnCount('3'); //是按下那个数字
}
void CMfc_CounterDlg::OnTwo() //按下了“2”
{
// TODO: Add your control notification handler code here
OnCount('2'); //是按下那个数字
}
void CMfc_CounterDlg::OnZero() //按下了“0”
{
// TODO: Add your control notification handler code here
OnCount('0'); //是按下那个数字
}
void CMfc_CounterDlg::OnAmount() //计算结果
{
// TODO: Add your control notification handler code here
m_isBtnDown=TRUE; //判断=号是否按下
m_secondNum=atof(m_number); //字符串转double
SetDlgItemText(IDC_EDIT1,m_number);
/*
计算结果
*/
if(m_countType=='+')//计算 和
{
m_count.Format("%lf",m_firstNum+m_secondNum);
}
else if(m_countType=='-')//计算 减
{
if(m_firstNum!=0)
{
m_count.Format("%lf",m_firstNum-m_secondNum);
}
else
{m_firstNum=m_secondNum;
m_count.Format("%lf",m_firstNum);
}
}
else if(m_countType=='*') //计算 乘
{
if(m_firstNum==0)
{
m_firstNum=1;
}
m_count.Format("%lf",m_firstNum*m_secondNum);
}
else if(m_countType=='/') //计算 除
{ if(m_firstNum==0)
{
m_firstNum=m_secondNum;
m_secondNum=1;
}
if(m_secondNum!=0)
{
m_count.Format("%lf",m_firstNum/m_secondNum);
}
else
{
m_number="被除数不能为0,重新输入!";
UpdateData(FALSE);
}
}
UpdateData(FALSE);
SetDlgItemText(IDC_EDIT1,m_count);
}