用Win32 SDK写一个简单的计算器
2010-07-11 20:44:36 来源:WEB开发网4.对操作符键用也一个函数表示:
//------按下操作符(+,-,*,/,sqrt,%,=)处理函数-----------
void EquResult()
{
//算出结果
if (strcmp(lpszOpt,"N")==0)
{
nResult1=strtod(lpszResult1,&stop);
}
else
{
switch(*lpszOpt) //比较上一次按的操作符后所得的结果
{
case ''+'':
nResult1=strtod(lpszResult1,&stop);
nResult2=strtod(lpszResult2,&stop);
nResult1=nResult1+nResult2;
break;
case ''-'':
nResult1=strtod(lpszResult1,&stop);
nResult2=strtod(lpszResult2,&stop);
nResult1=nResult1-nResult2;
break;
case ''*'':
nResult1=strtod(lpszResult1,&stop);
nResult2=strtod(lpszResult2,&stop);
nResult1=nResult1*nResult2;
break;
case ''/'':
nResult1=strtod(lpszResult1,&stop);
nResult2=strtod(lpszResult2,&stop);
if (nResult2==0)
{
MessageBox(hWndhWnd,"除数不能为零!","功能",MB_OK);
break;
}
nResult1=nResult1/nResult2;
break;
case ''%'':
nResult1=strtod(lpszResult1,&stop);
nResult1=nResult1/100;
break;
case ''S'':
nResult1=strtod(lpszResult1,&stop);
if (nResult1<0)
{
MessageBox(hWndhWnd,"负数没有平方根!","没意义",MB_OK); //hWndhWnd 表示全局变量的窗体句柄
break;
}
nResult=sqrt( nResult1 );
nResult1=nResult;
break;
}
}
nResult1=nResult1*1.0;
_gcvt(nResult1,15,lpszResult1); //双精度转化为字符串
SetWindowText(hEditResult,lpszResult1);
nOptF=0;
bDec=false;
}
更多精彩
赞助商链接