VC中怎么用MFC制作一个计算器
5个回答
展开全部
void CCalculatorDlg::OnButton0()
{
// TODO: Add your control notification handler code here
m_strShow+='0';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_strShow+='1';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton2()
{
// TODO: Add your control notification handler code here
m_strShow+='2';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton3()
{
// TODO: Add your control notification handler code here
m_strShow+='3';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton4()
{
// TODO: Add your control notification handler code here
m_strShow+='4';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton5()
{
// TODO: Add your control notification handler code here
m_strShow+='5';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton6()
{
// TODO: Add your control notification handler code here
m_strShow+='6';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton7()
{
// TODO: Add your control notification handler code here
m_strShow+='7';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton8()
{
// TODO: Add your control notification handler code here
m_strShow+='8';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton9()
{
// TODO: Add your control notification handler code here
m_strShow+='9';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButtonJia()
{
// TODO: Add your control notification handler code here
m_nType=1;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonEnd()
{
// TODO: Add your control notification handler code here
m_number2=atoi(m_strShow);
//m_number2=m_number2.parseDouble(m_strShow);
switch(m_nType)
{
case 1:
m_show=m_number1+m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
case 2:
m_show=m_number1-m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
case 3:
m_show=m_number1*m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
case 4:
m_show=m_number1/m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
}
}
void CCalculatorDlg::OnButtonC()
{
// TODO: Add your control notification handler code here
m_strShow="";
SetDlgItemInt(IDC_EDIT1,0);
}
void CCalculatorDlg::OnButtonJian()
{
// TODO: Add your control notification handler code here
m_nType=2;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonCheng()
{
// TODO: Add your control notification handler code here
m_nType=3;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonChu()
{
// TODO: Add your control notification handler code here
m_nType=4;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonBack()
{
// TODO: Add your control notification handler code here
m_strShow=m_strShow.Left(m_strShow.GetLength()-1);
//MessageBox(m_strShow);
SetDlgItemText(IDC_EDIT1,m_strShow);
// UpdateData(FALSE);
}
void CCalculatorDlg::OnButtonZf()
{
// TODO: Add your control notification handler code here
m_strShow.Insert(0,"-");
SetDlgItemText(IDC_EDIT1,m_strShow);
}
void CCalculatorDlg::OnButtonSqrt()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_EDIT1)->GetWindowText(m_strShow);
m_dbShow=atof(m_strShow);
m_dbShow=sqrt(m_dbShow);
static char ch[10]="";
sprintf(ch,"%lf",m_dbShow);
SetDlgItemText(IDC_EDIT1,ch);
}
void CCalculatorDlg::OnButtonFen()
{
// TODO: Add your control notification handler code here
// static double dou=m_strShow.Format("%lf",m_strShow);
GetDlgItem(IDC_EDIT1)->GetWindowText(m_strShow);
m_dbShow=atof(m_strShow);
m_dbShow=1/m_dbShow;
static char ch[10]="";
sprintf(ch,"%lf",m_dbShow);
SetDlgItemText(IDC_EDIT1,ch);
m_strShow.Empty();
sprintf(ch,"%d",0);
}
{
// TODO: Add your control notification handler code here
m_strShow+='0';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_strShow+='1';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton2()
{
// TODO: Add your control notification handler code here
m_strShow+='2';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton3()
{
// TODO: Add your control notification handler code here
m_strShow+='3';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton4()
{
// TODO: Add your control notification handler code here
m_strShow+='4';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton5()
{
// TODO: Add your control notification handler code here
m_strShow+='5';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton6()
{
// TODO: Add your control notification handler code here
m_strShow+='6';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton7()
{
// TODO: Add your control notification handler code here
m_strShow+='7';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton8()
{
// TODO: Add your control notification handler code here
m_strShow+='8';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton9()
{
// TODO: Add your control notification handler code here
m_strShow+='9';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButtonJia()
{
// TODO: Add your control notification handler code here
m_nType=1;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonEnd()
{
// TODO: Add your control notification handler code here
m_number2=atoi(m_strShow);
//m_number2=m_number2.parseDouble(m_strShow);
switch(m_nType)
{
case 1:
m_show=m_number1+m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
case 2:
m_show=m_number1-m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
case 3:
m_show=m_number1*m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
case 4:
m_show=m_number1/m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
}
}
void CCalculatorDlg::OnButtonC()
{
// TODO: Add your control notification handler code here
m_strShow="";
SetDlgItemInt(IDC_EDIT1,0);
}
void CCalculatorDlg::OnButtonJian()
{
// TODO: Add your control notification handler code here
m_nType=2;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonCheng()
{
// TODO: Add your control notification handler code here
m_nType=3;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonChu()
{
// TODO: Add your control notification handler code here
m_nType=4;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonBack()
{
// TODO: Add your control notification handler code here
m_strShow=m_strShow.Left(m_strShow.GetLength()-1);
//MessageBox(m_strShow);
SetDlgItemText(IDC_EDIT1,m_strShow);
// UpdateData(FALSE);
}
void CCalculatorDlg::OnButtonZf()
{
// TODO: Add your control notification handler code here
m_strShow.Insert(0,"-");
SetDlgItemText(IDC_EDIT1,m_strShow);
}
void CCalculatorDlg::OnButtonSqrt()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_EDIT1)->GetWindowText(m_strShow);
m_dbShow=atof(m_strShow);
m_dbShow=sqrt(m_dbShow);
static char ch[10]="";
sprintf(ch,"%lf",m_dbShow);
SetDlgItemText(IDC_EDIT1,ch);
}
void CCalculatorDlg::OnButtonFen()
{
// TODO: Add your control notification handler code here
// static double dou=m_strShow.Format("%lf",m_strShow);
GetDlgItem(IDC_EDIT1)->GetWindowText(m_strShow);
m_dbShow=atof(m_strShow);
m_dbShow=1/m_dbShow;
static char ch[10]="";
sprintf(ch,"%lf",m_dbShow);
SetDlgItemText(IDC_EDIT1,ch);
m_strShow.Empty();
sprintf(ch,"%d",0);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
视频你去看看!孙鑫的对话框。看第一个就行。要编就自己编功能!程序到后来是很复杂的!CString 这个看看
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
朋友,你是哪个学校的?别跟我说你是矿大的。其实我现在也在学MFC编程。要编个计算器,首先你得按照VC6提供的工具编一个对话框,再添加按钮,这两步不很难,关键是后面的工作:你得添加属于自己的函数去实现其功能。唉手机只能输120字,只能说这些了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用class wizard可以实现 不过这个程序还是有点复杂的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2009-12-12
展开全部
呵呵 你太天真了 这么小的地方 连程序都写不下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询