?? 計(jì)算器dlg.cpp
字號:
{
m_dnum=180/pi*m_dnum;
return m_dnum;
}
void CMyDlg::Onasin()
{
// TODO: Add your control notification handler code here
if(m_dnum>1)
{AfxMessageBox("函數(shù)輸入無效,出錯(cuò)");
m_dnum=0;
exit;
}
else
if(m_jiao==rad)
m_dnum=asin(m_dnum);
else
{
m_dnum=asin(m_dnum);
m_dnum=rad2ang(m_dnum);
}
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onacos()
{
// TODO: Add your control notification handler code here
if(m_dnum>1)
{AfxMessageBox("函數(shù)輸入無效,出錯(cuò)");
m_dnum=0;
exit;
}
else
if(m_jiao==rad)
m_dnum=acos(m_dnum);
else
{
m_dnum=acos(m_dnum);
m_dnum=rad2ang(m_dnum);
}
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onatan()
{
// TODO: Add your control notification handler code here
if(m_jiao==rad)
m_dnum=atan(m_dnum);
else
{
m_dnum=atan(m_dnum);
m_dnum=rad2ang(m_dnum);
}
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Ontanh()
{
// TODO: Add your control notification handler code here
if(m_jiao==rad)
m_dnum=tanh(m_dnum);
else
{
m_dnum=ang2rad(m_dnum);
m_dnum=tanh(m_dnum);
}
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onsin()
{
// TODO: Add your control notification handler code here
if(m_jiao==rad)
m_dnum=sin(m_dnum);
else
{
m_dnum=ang2rad(m_dnum);
m_dnum=sin(m_dnum);
}
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Oncos()
{
// TODO: Add your control notification handler code here
if(m_jiao==rad)
m_dnum=cos(m_dnum);
else
{
m_dnum=ang2rad(m_dnum);
m_dnum=cos(m_dnum);
}
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Ontan()
{
// TODO: Add your control notification handler code here
if(m_jiao==rad)
m_dnum=tan(m_dnum);
else
{
m_dnum=ang2rad(m_dnum);
m_dnum=tan(m_dnum);
}
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onsinh()
{
// TODO: Add your control notification handler code here
if(m_jiao==rad)
m_dnum=sinh(m_dnum);
else
{
m_dnum=ang2rad(m_dnum);
m_dnum=sinh(m_dnum);
}
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Oncosh()
{
// TODO: Add your control notification handler code here
if(m_jiao==rad)
m_dnum=cosh(m_dnum);
else
{
m_dnum=ang2rad(m_dnum);
m_dnum=cosh(m_dnum);
}
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onsqr()
{
// TODO: Add your control notification handler code here
if(m_dnum<0)
{AfxMessageBox("負(fù)數(shù)不可以開方,出錯(cuò)");
m_dnum=0;
exit;
}
else
m_dnum=sqrt(m_dnum);
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onx2()
{
// TODO: Add your control notification handler code here
m_dnum=pow(m_dnum,2);
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onx3()
{
// TODO: Add your control notification handler code here
m_dnum=pow(m_dnum,3);
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::On1x()
{
// TODO: Add your control notification handler code here
if(m_dnum==0)
{
AfxMessageBox("除數(shù)為零,出錯(cuò)");
m_dnum=0;
exit;
}
m_dnum=1.0/m_dnum;
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onn()
{
// TODO: Add your control notification handler code here
long i,k,n=(long)m_dnum;
if(m_dnum>=20)
{AfxMessageBox("階數(shù)太大,出錯(cuò)");
m_dnum=0;
exit;
}
for(i=1,k=1;i<=n;i++)
{
k=k*i;
}
m_dnum=(double)k;
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onlog()
{
// TODO: Add your control notification handler code here
m_dnum=log10(m_dnum);
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onln()
{
// TODO: Add your control notification handler code here
m_dnum=log(m_dnum);
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onex()
{
// TODO: Add your control notification handler code here
m_dnum=exp(m_dnum);
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onpi()
{
// TODO: Add your control notification handler code here
m_dnum=pi;
m_strbnum.Format("%.17lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::OnMplus()
{
// TODO: Add your control notification handler code here
m_mc=m_mc+m_dnum;
if(m_mc==0)
GetDlgItem(IDC_EDIT3)->SetWindowText(" ");
else
GetDlgItem(IDC_EDIT3)->SetWindowText("M");
}
void CMyDlg::OnMs()
{
// TODO: Add your control notification handler code here
m_mc=m_dnum;
if(m_mc==0)
GetDlgItem(IDC_EDIT3)->SetWindowText(" ");
else
GetDlgItem(IDC_EDIT3)->SetWindowText("M");
}
void CMyDlg::OnMr()
{
// TODO: Add your control notification handler code here
m_dnum=m_mc;
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::OnMc()
{
// TODO: Add your control notification handler code here
m_mc=0;
GetDlgItem(IDC_EDIT3)->SetWindowText(" ");
}
void CMyDlg::Onplusminus()
{
// TODO: Add your control notification handler code here
m_dnum=0-m_dnum;
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onhex()
{
// TODO: Add your control notification handler code here
m_sys=hex;
GetDlgItem(IDC_BUTTON2)->EnableWindow(true);
GetDlgItem(IDC_BUTTON3)->EnableWindow(true);
GetDlgItem(IDC_BUTTON4)->EnableWindow(true);
GetDlgItem(IDC_BUTTON5)->EnableWindow(true);
GetDlgItem(IDC_BUTTON6)->EnableWindow(true);
GetDlgItem(IDC_BUTTON7)->EnableWindow(true);
GetDlgItem(IDC_BUTTON8)->EnableWindow(true);
GetDlgItem(IDC_BUTTON9)->EnableWindow(true);
GetDlgItem(IDC_BUTTONA)->EnableWindow(true);
GetDlgItem(IDC_BUTTONB)->EnableWindow(true);
GetDlgItem(IDC_BUTTONC)->EnableWindow(true);
GetDlgItem(IDC_BUTTOND)->EnableWindow(true);
GetDlgItem(IDC_BUTTONE)->EnableWindow(true);
GetDlgItem(IDC_BUTTONF)->EnableWindow(true);
GetDlgItem(IDC_Dot)->EnableWindow(false);
GetDlgItem(IDC_pi)->EnableWindow(false);
GetDlgItem(IDC_asin)->EnableWindow(false);
GetDlgItem(IDC_acos)->EnableWindow(false);
GetDlgItem(IDC_atan)->EnableWindow(false);
GetDlgItem(IDC_tanh)->EnableWindow(false);
GetDlgItem(IDC_sin)->EnableWindow(false);
GetDlgItem(IDC_cos)->EnableWindow(false);
GetDlgItem(IDC_tan)->EnableWindow(false);
GetDlgItem(IDC_sinh)->EnableWindow(false);
GetDlgItem(IDC_cosh)->EnableWindow(false);
GetDlgItem(IDC_Exp)->EnableWindow(false);
GetDlgItem(IDC_x_y)->EnableWindow(false);
GetDlgItem(IDC_x_3)->EnableWindow(false);
GetDlgItem(IDC_x_2)->EnableWindow(false);
GetDlgItem(IDC_sqr)->EnableWindow(false);
GetDlgItem(IDC_e_x)->EnableWindow(false);
GetDlgItem(IDC_ln)->EnableWindow(false);
GetDlgItem(IDC_log)->EnableWindow(false);
GetDlgItem(IDC_n_)->EnableWindow(false);
GetDlgItem(IDC_1_x)->EnableWindow(false);
}
void CMyDlg::Ondec()
{
// TODO: Add your control notification handler code here
m_sys=dec;
GetDlgItem(IDC_BUTTON2)->EnableWindow(true);
GetDlgItem(IDC_BUTTON3)->EnableWindow(true);
GetDlgItem(IDC_BUTTON4)->EnableWindow(true);
GetDlgItem(IDC_BUTTON5)->EnableWindow(true);
GetDlgItem(IDC_BUTTON6)->EnableWindow(true);
GetDlgItem(IDC_BUTTON7)->EnableWindow(true);
GetDlgItem(IDC_BUTTON8)->EnableWindow(true);
GetDlgItem(IDC_BUTTON9)->EnableWindow(true);
GetDlgItem(IDC_BUTTONA)->EnableWindow(false);
GetDlgItem(IDC_BUTTONB)->EnableWindow(false);
GetDlgItem(IDC_BUTTONC)->EnableWindow(false);
GetDlgItem(IDC_BUTTOND)->EnableWindow(false);
GetDlgItem(IDC_BUTTONE)->EnableWindow(false);
GetDlgItem(IDC_BUTTONF)->EnableWindow(false);
GetDlgItem(IDC_Dot)->EnableWindow(true);
GetDlgItem(IDC_pi)->EnableWindow(true);
GetDlgItem(IDC_asin)->EnableWindow(true);
GetDlgItem(IDC_acos)->EnableWindow(true);
GetDlgItem(IDC_atan)->EnableWindow(true);
GetDlgItem(IDC_tanh)->EnableWindow(true);
GetDlgItem(IDC_sin)->EnableWindow(true);
GetDlgItem(IDC_cos)->EnableWindow(true);
GetDlgItem(IDC_tan)->EnableWindow(true);
GetDlgItem(IDC_sinh)->EnableWindow(true);
GetDlgItem(IDC_cosh)->EnableWindow(true);
GetDlgItem(IDC_Exp)->EnableWindow(true);
GetDlgItem(IDC_x_y)->EnableWindow(true);
GetDlgItem(IDC_x_3)->EnableWindow(true);
GetDlgItem(IDC_x_2)->EnableWindow(true);
GetDlgItem(IDC_sqr)->EnableWindow(true);
GetDlgItem(IDC_e_x)->EnableWindow(true);
GetDlgItem(IDC_ln)->EnableWindow(true);
GetDlgItem(IDC_log)->EnableWindow(true);
GetDlgItem(IDC_n_)->EnableWindow(true);
GetDlgItem(IDC_1_x)->EnableWindow(true);
}
void CMyDlg::Onoct()
{
// TODO: Add your control notification handler code here
m_sys=oct;
GetDlgItem(IDC_BUTTON2)->EnableWindow(true);
GetDlgItem(IDC_BUTTON3)->EnableWindow(true);
GetDlgItem(IDC_BUTTON4)->EnableWindow(true);
GetDlgItem(IDC_BUTTON5)->EnableWindow(true);
GetDlgItem(IDC_BUTTON6)->EnableWindow(true);
GetDlgItem(IDC_BUTTON7)->EnableWindow(true);
GetDlgItem(IDC_BUTTON8)->EnableWindow(false);
GetDlgItem(IDC_BUTTON9)->EnableWindow(false);
GetDlgItem(IDC_BUTTONA)->EnableWindow(false);
GetDlgItem(IDC_BUTTONB)->EnableWindow(false);
GetDlgItem(IDC_BUTTONC)->EnableWindow(false);
GetDlgItem(IDC_BUTTOND)->EnableWindow(false);
GetDlgItem(IDC_BUTTONE)->EnableWindow(false);
GetDlgItem(IDC_BUTTONF)->EnableWindow(false);
GetDlgItem(IDC_Dot)->EnableWindow(false);
GetDlgItem(IDC_pi)->EnableWindow(false);
GetDlgItem(IDC_asin)->EnableWindow(false);
GetDlgItem(IDC_acos)->EnableWindow(false);
GetDlgItem(IDC_atan)->EnableWindow(false);
GetDlgItem(IDC_tanh)->EnableWindow(false);
GetDlgItem(IDC_sin)->EnableWindow(false);
GetDlgItem(IDC_cos)->EnableWindow(false);
GetDlgItem(IDC_tan)->EnableWindow(false);
GetDlgItem(IDC_sinh)->EnableWindow(false);
GetDlgItem(IDC_cosh)->EnableWindow(false);
GetDlgItem(IDC_Exp)->EnableWindow(false);
GetDlgItem(IDC_x_y)->EnableWindow(false);
GetDlgItem(IDC_x_3)->EnableWindow(false);
GetDlgItem(IDC_x_2)->EnableWindow(false);
GetDlgItem(IDC_sqr)->EnableWindow(false);
GetDlgItem(IDC_e_x)->EnableWindow(false);
GetDlgItem(IDC_ln)->EnableWindow(false);
GetDlgItem(IDC_log)->EnableWindow(false);
GetDlgItem(IDC_n_)->EnableWindow(false);
GetDlgItem(IDC_1_x)->EnableWindow(false);
}
void CMyDlg::Onbin()
{
// TODO: Add your control notification handler code here
m_sys=bin;
GetDlgItem(IDC_BUTTON2)->EnableWindow(false);
GetDlgItem(IDC_BUTTON3)->EnableWindow(false);
GetDlgItem(IDC_BUTTON4)->EnableWindow(false);
GetDlgItem(IDC_BUTTON5)->EnableWindow(false);
GetDlgItem(IDC_BUTTON6)->EnableWindow(false);
GetDlgItem(IDC_BUTTON7)->EnableWindow(false);
GetDlgItem(IDC_BUTTON8)->EnableWindow(false);
GetDlgItem(IDC_BUTTON9)->EnableWindow(false);
GetDlgItem(IDC_BUTTONA)->EnableWindow(false);
GetDlgItem(IDC_BUTTONB)->EnableWindow(false);
GetDlgItem(IDC_BUTTONC)->EnableWindow(false);
GetDlgItem(IDC_BUTTOND)->EnableWindow(false);
GetDlgItem(IDC_BUTTONE)->EnableWindow(false);
GetDlgItem(IDC_Dot)->EnableWindow(false);
GetDlgItem(IDC_pi)->EnableWindow(false);
GetDlgItem(IDC_asin)->EnableWindow(false);
GetDlgItem(IDC_acos)->EnableWindow(false);
GetDlgItem(IDC_atan)->EnableWindow(false);
GetDlgItem(IDC_tanh)->EnableWindow(false);
GetDlgItem(IDC_sin)->EnableWindow(false);
GetDlgItem(IDC_cos)->EnableWindow(false);
GetDlgItem(IDC_tan)->EnableWindow(false);
GetDlgItem(IDC_sinh)->EnableWindow(false);
GetDlgItem(IDC_cosh)->EnableWindow(false);
GetDlgItem(IDC_Exp)->EnableWindow(false);
GetDlgItem(IDC_x_y)->EnableWindow(false);
GetDlgItem(IDC_x_3)->EnableWindow(false);
GetDlgItem(IDC_x_2)->EnableWindow(false);
GetDlgItem(IDC_sqr)->EnableWindow(false);
GetDlgItem(IDC_e_x)->EnableWindow(false);
GetDlgItem(IDC_ln)->EnableWindow(false);
GetDlgItem(IDC_log)->EnableWindow(false);
GetDlgItem(IDC_n_)->EnableWindow(false);
GetDlgItem(IDC_1_x)->EnableWindow(false);
}
void CMyDlg::OnBackspace() //點(diǎn)擊"Backspace"按鈕修正輸入數(shù)
{
// TODO: Add your control notification handler code here
// 點(diǎn)擊"Backspace"按鈕修正輸入數(shù)
if(m_strbnum=="") return;
m_strbnum.Delete(m_strbnum.GetLength()-1,1);
UpdateData(false);
}
void CMyDlg::OnNot()
{
// TODO: Add your control notification handler code here
unsigned a;
a=unsigned int(m_dnum);
m_dnum=~a;
if(m_sys==dec)
{
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
m_bnext=TRUE;
}
else
{
if(m_sys==hex)
m_strbnum.Format("%X",long(m_dnum));
else
if(m_sys==oct)
m_strbnum.Format("%o",long(m_dnum));
if(m_sys==bin)
{
unsigned int num,bitMask=0x8000;//掩碼
int i;
num=(unsigned int)m_dnum;
m_strbnum="";
for (i=1;i<=16;i++)
{
m_strbnum=m_strbnum+(num&bitMask ? "1" : "0" );
bitMask >>=1;
}
}
UpdateData(FALSE);
}
}
void CMyDlg::Onangle()
{
// TODO: Add your control notification handler code here
if(m_jiao!=angle)
m_dnum=rad2ang(m_dnum);
m_jiao=angle;
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::Onrad()
{
// TODO: Add your control notification handler code here
if(m_jiao!=rad)
m_dnum=ang2rad(m_dnum);
m_jiao=rad;
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
void CMyDlg::OnExp()
{
// TODO: Add your control notification handler code here
m_dnum=exp(m_dnum);
m_strbnum.Format("%.12lf",m_dnum);//精度最高保留到小數(shù)點(diǎn)后6位
m_strbnum.TrimRight('0');//去除右邊起連續(xù)出現(xiàn)的0
m_strbnum.TrimRight('.');//去除右邊出現(xiàn)的.
UpdateData(FALSE);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -