C语言 简易计算器源文件.docx
- 文档编号:23383366
- 上传时间:2023-05-16
- 格式:DOCX
- 页数:17
- 大小:15.96KB
C语言 简易计算器源文件.docx
《C语言 简易计算器源文件.docx》由会员分享,可在线阅读,更多相关《C语言 简易计算器源文件.docx(17页珍藏版)》请在冰豆网上搜索。
C语言简易计算器源文件
#include"stdafx.h"
#include
#include
#include
#include"resource.h"
#include"MainDlg.h"
#definePI3.141592653589793
/*
TemplatedesignedbyRuP.Pleasevisitformoreinformation
如鹏网()大学生计算机学习社区,提供大量免费视频学习教程,提供个性化一对一学习指导
*/
BOOLWINAPIMain_Proc(HWNDhWnd,UINTuMsg,WPARAMwParam,LPARAMlParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd,WM_INITDIALOG,Main_OnInitDialog);
HANDLE_MSG(hWnd,WM_COMMAND,Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE,Main_OnClose);
}
returnFALSE;
}
BOOLMain_OnInitDialog(HWNDhwnd,HWNDhwndFocus,LPARAMlParam)
{
returnTRUE;
}
voidMain_OnCommand(HWNDhwnd,intid,HWNDhwndCtl,UINTcodeNotify)
{
TCHARnumber1[256]={0};
TCHARnumber2[256]={0};
TCHARnumber3[256]={0};
TCHARnumber[256]={0};
staticdoublenum1;
doublenum2;
TCHARbuffer[256];
staticflag=0;
staticPOINTflag=0;
staticEQUALSflag=0;
staticSYMBOLSSflag=0;
switch(id)
{
caseID_MENUITEMTHEME:
{
MessageBox(hwnd,TEXT("本计算器于2010-12-20,14:
28完成,制作:
泸诚"),TEXT("版本信息"),MB_OK);
}
break;
caseID_MENUITEMHEL:
{
MessageBox(hwnd,TEXT("本能进行加、减、乘、除、三数函数、乘方运算,只要你能打开它,肯定就能用它,否则肯定属木瓜!
:
)"),TEXT("关于计算器"),MB_OK);
}
break;
caseIDC_SIN:
{
EQUALSflag=1;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
doublen1=atof(number1);
doubleresult=sin(n1*PI/180);
*gcvt(result,10,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
break;
caseIDC_COS:
{
doubleresult=0;
EQUALSflag=1;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
doublen1=atof(number1);
if(int(n1/90)%2==0)
{
result=cos(n1*PI/180);
}
*gcvt(result,10,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
break;
caseIDC_TAN:
{
EQUALSflag=1;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
doublen1=atof(number1);
if(int(n1/90)%2==0)
{
doubleresult=tan(n1*PI/180);
*gcvt(result,10,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
else
{
wsprintf(number1,"error");
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
}
break;
caseIDC_ARS:
{
EQUALSflag=1;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
doublen1=atof(number1);
doubleresult=asin(n1)*180/PI;
*gcvt(result,10,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
break;
caseIDC_ARC:
{
EQUALSflag=1;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
doublen1=atof(number1);
doubleresult=acos(n1)*180/PI;
*gcvt(result,10,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
break;
caseIDC_ART:
{
EQUALSflag=1;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
doublen1=atof(number1);
doubleresult=atan(n1)*180/PI;
*gcvt(result,10,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
break;
caseIDC_BACKSPACE:
{
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
intnn=strlen(number1);
inti=0;
TCHARstr[256];
for(i=0;i<(nn-1);i++)
{
str[i]=number1[i];
}
str[i]='\0';
SetDlgItemText(hwnd,IDC_NUMBER1,str);
}
break;
caseIDC_CE:
{
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
break;
caseIDC_C:
{
SetDlgItemText(hwnd,IDC_NUMBER1,"");
POINTflag=0;
EQUALSflag=0;
SYMBOLSSflag=0;
}
break;
caseIDC_SYMBOLS:
{
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
doublen1=atof(number1);
n1=(-n1);
*gcvt(n1,10,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
break;
caseIDC_DIG0:
{
if(EQUALSflag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s0",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
}
break;
caseIDC_DIG1:
{
if(flag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s1",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
}
break;
caseIDC_DIG2:
{
if(EQUALSflag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s2",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
}
break;
caseIDC_DIG3:
{
if(EQUALSflag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s3",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
}
break;
caseIDC_DIG4:
{
if(EQUALSflag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s4",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
}
break;
caseIDC_DIG5:
{
if(EQUALSflag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s5",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
}
break;
caseIDC_DIG6:
{
if(EQUALSflag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s6",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
}
break;
caseIDC_DIG7:
{
if(EQUALSflag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s7",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
}
break;
caseIDC_DIG8:
{
if(EQUALSflag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s8",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
}
break;
caseIDC_DIG9:
{
if(EQUALSflag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s9",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
}
break;
caseIDC_POINT:
{
TCHARbuffer[256];
if(EQUALSflag==1)
{
EQUALSflag=0;
SetDlgItemText(hwnd,IDC_NUMBER1,"");
}
if(POINTflag!
=1)
{
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
wsprintf(buffer,"%s.",number1);
SetDlgItemText(hwnd,IDC_NUMBER1,buffer);
POINTflag=1;
}
}
break;
caseIDC_PLUS:
{
POINTflag=0;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
num1=atof(number1);
SetDlgItemText(hwnd,IDC_NUMBER1,"");
flag=1;
}
break;
caseIDC_MINUS:
{
POINTflag=0;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
num1=atof(number1);
SetDlgItemText(hwnd,IDC_NUMBER1,"");
flag=2;
}
break;
caseIDC_TIMES:
{
POINTflag=0;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
num1=atof(number1);
SetDlgItemText(hwnd,IDC_NUMBER1,"");
flag=3;
}
break;
caseIDC_DIVIDE:
{
POINTflag=0;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
num1=atof(number1);
SetDlgItemText(hwnd,IDC_NUMBER1,"");
flag=4;
}
break;
caseIDC_CHENGFANG:
{
POINTflag=0;
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
num1=atof(number1);
SetDlgItemText(hwnd,IDC_NUMBER1,"");
flag=5;
}
break;
caseIDC_EQUALS:
{
EQUALSflag=1;
POINTflag=0;
if(flag==1)
{
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
num2=atof(number1);
doublesum=num1+num2;
*gcvt(sum,15,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
if(flag==2)
{
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
num2=atof(number1);
doublesum=num1-num2;
*gcvt(sum,15,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
if(flag==3)
{
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
num2=atof(number1);
doublesum=num1*num2;
*gcvt(sum,15,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
if(flag==4)
{
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
num2=atof(number1);
doublesum=num1/num2;
*gcvt(sum,15,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
if(flag==5)
{
GetDlgItemText(hwnd,IDC_NUMBER1,number1,sizeof(number1));
num2=atof(number1);
doublesum=pow(num1,num2);
*gcvt(sum,15,number1);
SetDlgItemText(hwnd,IDC_NUMBER1,number1);
}
flag=0;
}
break;
default:
break;
}
}
voidMain_OnClose(HWNDhwnd)
{
EndDialog(hwnd,0);
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C语言 简易计算器源文件 语言 简易 计算器 源文件