www.pudn.com > 仿Windows的自带计算器 .rar > Calcul.c
#include "stdio.h"
#include "string.h"
#include "math.h"
#include "stdlib.h"
#include "graphics.h"
#include "bios.h"
#include "dos.h"
#define NUM0 0x5230
#define NUM1 0x4f31
#define NUM2 0x5032
#define NUM3 0x5133
#define NUM4 0x4b34
#define NUM5 0x4c35
#define NUM6 0x4d36
#define NUM7 0x4737
#define NUM8 0x4838
#define NUM9 0x4939
#define NUMPNT 0x532e
#define NUMADD 0x4e2b
#define NUMSUB 0x4a2d
#define NUMMUL 0x372a
#define NUMDIV 0x352f
#define NUMEQU 0x1c0d
#define KEY0 0xb30
#define KEY1 0x231
#define KEY2 0x332
#define KEY3 0x433
#define KEY4 0x534
#define KEY5 0x635
#define KEY6 0x736
#define KEY7 0x837
#define KEY8 0x938
#define KEY9 0xa39
#define KEYPNT 0x342e
#define KEYSUB 0xc2d
#define KEYMUL 0x92a
#define KEYEQU 0xd3d
#define SQR 0x340
#define KEYR 0x1372
#define PERCENT 0x025
#define DEL 0x5300
#define ESC 0x11b
#define BACKPLACE 0xe08
#define F9 0x4300
#define CTRL_L 0x260c
#define CTRL_R 0x1312
#define CTRL_M 0x320d
#define CTRL_P 0x1910
#define ALT_X 0x2d00
#define TRUE 1
#define FALSE 0
struct Block
{ int left,top,width,height;
char caption[50];
int fontcolor,fontsize,status;
};
void Form(struct Block form);
void TextBox(struct Block txtbox);
void Label(struct Block label);
void CommandButton(struct Block cmdbutton);
void CommandButton_MouseDown(int i);
void CommandButton_DragOver(int i);
void CommandButton_MouseUp(int i);
void CommandButton_DragDrop();
void CommandButton_MouseMove();
char ResetMouse();
void ShowMouse();
void HideMouse();
int MouseLP();
int MouseRP();
void GetMousePos(int *x,int *y);
void InitApp();
void Showme();
void Load();
void CommandButton_Click(int key);
void DoubleRun();
void SingleRun(int operator);
void Resetbuf();
void StoreSet(int key);
void Unload();
struct Block frmmain,txtscreen,lblstore,cmdbutton[28];
int clickflag,index,mouseinflag;
int top,pointflag,digitkeyhit;
int operator,runflag,ctnflag;
int errorflag;
double num1,num2,store;
char strbuf[33];
void main()
{
int i;
int mouse_x,mouse_y;
int key;
InitApp();
Showme();
Load();
while(1)
{ key=index;
GetMousePos(&mouse_x,&mouse_y);
for(i=0;i<28;i++)
if(frmmain.left+cmdbutton[i].left1)
if(strbuf[--top]=='.')
{ if(strbuf[1]=='0'&&strbuf[2]=='.')
strbuf[--top]=0;
else
strbuf[top]=0;
pointflag=FALSE;
}
else
strbuf[top]=0;
operator=0;
ctnflag=FALSE;
runflag=FALSE;
strcpy(txtscreen.caption,strbuf);
break;
case 26:
Resetbuf();
num1=0;
strcpy(txtscreen.caption,strbuf);
TextBox(txtscreen);
break;
case 27:
Resetbuf();
num1=num2=0;
ctnflag=FALSE;
operator=0;
runflag=FALSE;
errorflag=FALSE;
strcpy(txtscreen.caption,"0.");
TextBox(txtscreen);
break;
case 0:
Unload();
break;
}
if(errorflag==FALSE)
{ if(atof(txtscreen.caption)==0)
strcpy(txtscreen.caption,"0");
if(strchr(txtscreen.caption,'.')==NULL)
strcat(txtscreen.caption,".");
}
TextBox(txtscreen);
}
void DoubleRun()
{ switch(operator)
{ case 13: num2+=num1;break;
case 14: num2-=num1;break;
case 15: num2*=num1;break;
case 16: if(num1==0)
errorflag=TRUE;
else
num2/=num1;
break;
}
if(errorflag)
strcpy(txtscreen.caption,"Can't divide by zero!");
else
sprintf(txtscreen.caption,"%G",num2);
}
void SingleRun(int key)
{ switch(key)
{ case 17:
if(num1<0)
errorflag=TRUE;
else
num1=sqrt(num1);
break;
case 18:
num1/=100;
break;
case 19:
if(num1==0)
errorflag=TRUE;
else
num1=1/num1;
break;
}
if(errorflag==TRUE)
if(num1<0)
strcpy(txtscreen.caption,"Can't blower than zero!");
else
strcpy(txtscreen.caption,"Can't equal to zero!");
else
sprintf(txtscreen.caption,"%G",num1);
}
void StoreSet(int key)
{ switch(key)
{ case 21:
store=0;
lblstore.caption[0]=0;
break;
case 22:
num1=store;
sprintf(txtscreen.caption,"%G",store);
runflag=FALSE;
if(ctnflag==FALSE) operator=0;
break;
case 23:
store=num1;
strcpy(lblstore.caption,"M");
break;
case 24:
store+=num1;
strcpy(lblstore.caption,"M");
break;
}
Label(lblstore);
}
char ResetMouse()
{ union REGS r;
r.x.ax=0;
int86(0x33,&r,&r);
if(r.x.ax==0)
return 0;
else
return 1;
}
void ShowMouse()
{ union REGS r;
r.x.ax=1;
int86(0x33,&r,&r);
}
void HideMouse()
{ union REGS r;
r.x.ax=2;
int86(0x33,&r,&r);
}
int MouseLP()
{ union REGS r;
r.x.ax=3;
int86(0x33,&r,&r);
return(r.x.bx&1);
}
int MouseRP()
{ union REGS r;
r.x.ax=3;
int86(0x33,&r,&r);
return(r.x.bx&2);
}
void GetMousePos(int *x,int *y)
{ union REGS r;
r.x.ax=3;
int86(0x33,&r,&r);
*x=r.x.cx;
*y=r.x.dx;
}