Code:
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include "..\MouseHandler.h" // ajustar o caminho ao seu projecto
#include "..\calcSkinLib.h" // ajustar o caminho ao seu projecto
#define PI = 3.1415;
char tecla(struct mouseClick evento, HANDLE wHnd);
int main(int argc, char *argv[]) {
HANDLE rHnd, wHnd; //Handles for reading and writing to the console.
struct mouseClick evento;
if (!initializeControls(&rHnd, &wHnd)) { //must call before doing anything
printf("ERROR WHILE INITIALIZING\n"); //if couldn't initialize
exit(0);
}
printCalcMask(wHnd);
locate(79, 24, wHnd); printf("\xb2");
locate(0, 0, wHnd); printf(" clique em no ecr\xc6 (em [24, 79] para encerrar)");
do {
char num1[20]; char opr;
double n1 = 0; double n2 = 0; double rslt = 0;
char mClick;
int l1 = 0;
do{
evento = readMouse(rHnd);
locate(0, 0, wHnd);
mClick = tecla(evento, wHnd);
locate(25 + l1, 6, wHnd);
switch (mClick){
case '0':num1[l1] = '0'; /*locate(35 + l1, 6, wHnd);*/ printf("0"); break;
case '1':num1[l1] = '1'; /*locate(35 + l1, 6, wHnd);*/ printf("1"); break;
case '2':num1[l1] = '2'; /*locate(35 + l1, 6, wHnd);*/ printf("2"); break;
case '3':num1[l1] = '3'; /*locate(35 + l1, 6, wHnd);*/ printf("3"); break;
case '.':num1[l1] = '.'; /*locate(35 + l1, 6, wHnd);*/ printf("."); break;
case '4':num1[l1] = '4'; /*locate(35 + l1, 6, wHnd);*/ printf("4"); break;
case '5':num1[l1] = '5'; /*locate(35 + l1, 6, wHnd);*/ printf("5"); break;
case '6':num1[l1] = '6'; /*locate(35 + l1, 6, wHnd);*/ printf("6"); break;
case '7':num1[l1] = '7'; /*locate(35 + l1, 6, wHnd);*/ printf("7"); break;
case '8':num1[l1] = '8'; /*locate(35 + l1, 6, wHnd);*/ printf("8"); break;
case '9':num1[l1] = '9'; /*locate(35 + l1, 6, wHnd);*/ printf("9"); break;
case 'C':for (int j = 0; j <= 20; j++){ num1[j] = ' '; }l1 = 0; n1 = 0; n2 = 0; locate(25, 6, wHnd); printf("\t\t\t "); break;
case 'p':num1[0] = '3'; num1[1] = '.'; num1[2] = '1'; num1[3] = '4'; num1[4] = '1'; num1[5] = '5';
locate(25, 6, wHnd); printf("\t\t\t"); locate(25 + l1, 6, wHnd); printf(" pi"); l1 = 0; break;
case '-':{ opr = '-'; locate(25, 6, wHnd); printf("\t\t\t ");
if (n2 == 0) {
n2 = n1;
for (int j = 0; j <= 20; j++){
num1[j] = ' ';
}
}
l1 = 0; } break;
case '+':{ opr = '+'; locate(25, 6, wHnd); printf("\t\t\t ");
if (n2 == 0) {
n2 = n1;
for (int j = 0; j <= 20; j++){
num1[j] = ' ';
}
}
l1 = 0; } break;
case '*':{ opr = '*'; locate(25, 6, wHnd); printf("\t\t\t ");
if (n2 == 0) {
n2 = n1;
for (int j = 0; j <= 20; j++){
num1[j] = ' ';
}
}
l1 = 0; } break;
case '/':{ opr = '/'; locate(25, 6, wHnd); printf("\t\t\t ");
if (n2 == 0) {
n2 = n1;
for (int j = 0; j <= 20; j++){
num1[j] = ' ';
}
}
l1 = 0; } break;
case '=':
switch (opr){
case '+':locate(25, 6, wHnd); printf("\t\t\t"); locate(25, 6, wHnd); n2 += n1; printf("%.4f", n2);
for (int j = 0; j <= 20; j++){ num1[j] = ' '; }l1 = 0; break;
case '-':locate(25, 6, wHnd); printf("\t\t\t"); locate(25, 6, wHnd); n2 = n2 - n1; printf("%.4f", n2); l1 = 0;
for (int j = 0; j <= 20; j++){ num1[j] = ' '; } break;
case '*':locate(25, 6, wHnd); printf("\t\t\t"); locate(25, 6, wHnd); n2 = n2 * n1; printf("%.4f", n2); l1 = 0;
for (int j = 0; j <= 20; j++){ num1[j] = ' '; } break;
case '/':locate(25, 6, wHnd); printf("\t\t\t"); locate(25, 6, wHnd); n2 = n2 / n1; printf("%.4f", n2); l1 = 0;
for (int j = 0; j <= 20; j++){ num1[j] = ' '; } break;
}
//if (opr == '+'){ locate(36, 6, wHnd); printf("\t\t"); locate(36, 3, wHnd); n2+=n1; printf("%.4f",n2); }
// else if (opr == '-'){ locate(36, 6, wHnd); printf("\t\t"); locate(36, 3, wHnd); n2 =n2- n1; printf("%.4f", n2); }
}//switch
if
(l1 <= 15)
{
l1++;
}
n1 = atof(num1);
} while (!(mClick == 'o'));
} while (!(evento.xPos == 79 && evento.yPos == 24));
locate(0, 1, wHnd);
printf("Pressione uma tecla para fechar...\x07"); _getch();
return EXIT_SUCCESS;
}
char tecla(struct mouseClick evento, HANDLE wHnd){
if (evento.xPos >= 30 && evento.xPos <= 32 && evento.yPos == 10) return 'x'; //exit
if (evento.xPos >= 35 && evento.xPos <= 37 && evento.yPos == 10) return 'f';//fix
if (evento.xPos >= 39 && evento.xPos <= 41 && evento.yPos == 10) return 'b';//back
if (evento.xPos >= 44 && evento.xPos <= 47 && evento.yPos == 10) return 'c';//ce
if (evento.xPos >= 49 && evento.xPos <= 51 && evento.yPos == 10) return 'C';//c
if (evento.xPos >= 26 && evento.xPos <= 28 && evento.yPos == 12) return 'i';//inv
if (evento.xPos >= 30 && evento.xPos <= 32 && evento.yPos == 12) return 's';//sin
if (evento.xPos >= 34 && evento.xPos <= 36 && evento.yPos == 12) return 'o';//cos
if (evento.xPos >= 38 && evento.xPos <= 40 && evento.yPos == 12) return 't';//tan
if (evento.xPos >= 42 && evento.xPos <= 43 && evento.yPos == 12) return 'n';//ln
if (evento.xPos >= 45 && evento.xPos <= 47 && evento.yPos == 12) return 'l';//log
if (evento.xPos >= 49 && evento.xPos <= 51 && evento.yPos == 12) return 'e';//exp
if (evento.xPos >= 26 && evento.xPos <= 28 && evento.yPos == 14) return '7';//7
if (evento.xPos >= 30 && evento.xPos <= 32 && evento.yPos == 14) return '8';//8
if (evento.xPos >= 34 && evento.xPos <= 36 && evento.yPos == 14) return '9';//9
if (evento.xPos >= 38 && evento.xPos <= 40 && evento.yPos == 14) return '/';// /
if (evento.xPos >= 42 && evento.xPos <= 45 && evento.yPos == 14) return 'm';// mc
if (evento.xPos >= 47 && evento.xPos <= 51 && evento.yPos == 14) return 'q';//raiz
if (evento.xPos >= 26 && evento.xPos <= 28 && evento.yPos == 16) return '4';//4
if (evento.xPos >= 30 && evento.xPos <= 32 && evento.yPos == 16) return '5';//5
if (evento.xPos >= 34 && evento.xPos <= 36 && evento.yPos == 16) return '6';//6
if (evento.xPos >= 38 && evento.xPos <= 40 && evento.yPos == 16) return '*';//*
if (evento.xPos >= 42 && evento.xPos <= 44 && evento.yPos == 16) return 'M';//mr
if (evento.xPos >= 47 && evento.xPos <= 49 && evento.yPos == 16) return 'p';//pi
if (evento.xPos >= 26 && evento.xPos <= 28 && evento.yPos == 18) return '1';//1
if (evento.xPos >= 30 && evento.xPos <= 32 && evento.yPos == 18) return '2';//2
if (evento.xPos >= 34 && evento.xPos <= 36 && evento.yPos == 18) return '3';//3
if (evento.xPos >= 38 && evento.xPos <= 40 && evento.yPos == 18) return '-';//-
if (evento.xPos >= 42 && evento.xPos <= 45 && evento.yPos == 18) return '&';//ms
if (evento.xPos >= 47 && evento.xPos <= 51 && evento.yPos == 18) return 'r';//rad
if (evento.xPos >= 26 && evento.xPos <= 28 && evento.yPos == 20) return '.';// .
if (evento.xPos >= 30 && evento.xPos <= 32 && evento.yPos == 20) return '0';//0
if (evento.xPos >= 34 && evento.xPos <= 36 && evento.yPos == 20) return '=';// =
if (evento.xPos >= 38 && evento.xPos <= 40 && evento.yPos == 20) return '+';// +
if (evento.xPos >= 42 && evento.xPos <= 45 && evento.yPos == 20) return '#';//m+
if (evento.xPos >= 47 && evento.xPos <= 51 && evento.yPos == 20) return 'd';//deg
}