📄 calculator.c
字号:
#include <fcntl.h>
#include <termios.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <minigui/mgext.h>
#define IDC_CBUTTON0 0x102b
#define IDC_CBUTTON1 0x102c
#define IDC_CBUTTON2 0x102d
#define IDC_CBUTTON3 0x102e
#define IDC_CBUTTON4 0x102f
#define IDC_CBUTTON5 0x1030
#define IDC_CBUTTON6 0x1031
#define IDC_CBUTTON7 0x1032
#define IDC_CBUTTON8 0x1033
#define IDC_CBUTTON9 0x1034
#define IDC_CBUTTON_OK 0x1037
#define IDC_CBUTTON_CE 0x1038
#define IDC_CBUTTON_B 0x1039
#define IDC_CBUTTON_ADD 0x103a
#define IDC_CBUTTON_SUB 0x103b
#define IDC_CBUTTON_MUL 0x103c
#define IDC_CBUTTON_DIV 0x103d
#define IDC_CBUTTON_POINT 0x103e
#define IDC_CEDIT 0x103f
#define CMAX1 30
#define IDC_CBUTTON_RE 0x1060
static BITMAP bmp_bkgnd;
int Cflag1=0;
int Cflag2=0;
int Cflag3=0;
static void CeateCounterButton(HWND Chcwd)
{
CreateWindow(CTRL_BUTTON,
"0",WS_VISIBLE, IDC_CBUTTON0, 100,155,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"1",WS_VISIBLE, IDC_CBUTTON1, 100,125,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"2",WS_VISIBLE, IDC_CBUTTON2, 130,125,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"3",WS_VISIBLE, IDC_CBUTTON3, 160,125,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"4",WS_VISIBLE, IDC_CBUTTON4, 100,95,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"5",WS_VISIBLE, IDC_CBUTTON5, 130,95,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"6",WS_VISIBLE, IDC_CBUTTON6, 160,95,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"7",WS_VISIBLE, IDC_CBUTTON7, 100,65,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"8",WS_VISIBLE, IDC_CBUTTON8, 130,65,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"9",WS_VISIBLE, IDC_CBUTTON9, 160,65,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"=",WS_VISIBLE, IDC_CBUTTON_OK, 160,155,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"CE",WS_VISIBLE, IDC_CBUTTON_CE, 160,35,60,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"backspace",WS_VISIBLE, IDC_CBUTTON_B, 100,35,60,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"+",WS_VISIBLE, IDC_CBUTTON_ADD, 190,65,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"-",WS_VISIBLE, IDC_CBUTTON_SUB, 190,95,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"*",WS_VISIBLE, IDC_CBUTTON_MUL, 190,125,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"/",WS_VISIBLE, IDC_CBUTTON_DIV, 190,155,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
".",WS_VISIBLE, IDC_CBUTTON_POINT, 130,155,30,30, Chcwd, 0);
CreateWindow(CTRL_BUTTON,
"return",WS_VISIBLE, IDC_CBUTTON_RE, 270,160,50,30, Chcwd, 0);
}
static int CalculatorProc(HWND Chcwd, int message, WPARAM wParam, LPARAM lParam)
{
static HWND Med;
HDC hdc;
char Cbuf[CMAX1];
char Cbuffer[CMAX1];
static char Cbuff[CMAX1];
static char Ctemp1[CMAX1]={'+','\0'};
static char Ctemp2[CMAX1]={'-','\0'};
static char Ctemp3[CMAX1]={'*','\0'};
static char Ctemp4[CMAX1]={'/','\0'};
int Clen;
static float Ftemp1;
static float Ftemp;
static float sum;
char *str;
//static int a,b,c,d;
switch(message)
{
case MSG_CREATE:
CeateCounterButton(Chcwd);
Med = CreateWindow(CTRL_EDIT,
"",WS_VISIBLE | WS_BORDER,
IDC_CEDIT,
40,0,240,25,
Chcwd,
0);
SetFocus(Med);
return 0;
case MSG_COMMAND:
switch(wParam)
{
case IDC_CBUTTON1:
if (Cflag3==1)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
Cbuffer[0]='\0';
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
}
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
strcpy(Cbuf,"1");
strcat(Cbuffer,Cbuf);
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
Cflag3=0;
return 0;
case IDC_CBUTTON2:
if (Cflag3==1)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
Cbuffer[0]='\0';
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
}
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
strcpy(Cbuf,"2");
strcat(Cbuffer,Cbuf);
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
Cflag3=0;
return 0;
case IDC_CBUTTON3:
if (Cflag3==1)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
Cbuffer[0]='\0';
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
}
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
strcpy(Cbuf,"3");
strcat(Cbuffer,Cbuf);
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
Cflag3=0;
return 0;
case IDC_CBUTTON4:
if (Cflag3==1)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
Cbuffer[0]='\0';
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
}
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
strcpy(Cbuf,"4");
strcat(Cbuffer,Cbuf);
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
Cflag3=0;
return 0;
case IDC_CBUTTON5:
if (Cflag3==1)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
Cbuffer[0]='\0';
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
}
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
strcpy(Cbuf,"5");
strcat(Cbuffer,Cbuf);
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
Cflag3=0;
return 0;
case IDC_CBUTTON6:
if (Cflag3==1)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
Cbuffer[0]='\0';
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
}
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
strcpy(Cbuf,"6");
strcat(Cbuffer,Cbuf);
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
Cflag3=0;
return 0;
case IDC_CBUTTON7:
if (Cflag3==1)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
Cbuffer[0]='\0';
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
}
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
strcpy(Cbuf,"7");
strcat(Cbuffer,Cbuf);
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
Cflag3=0;
return 0;
case IDC_CBUTTON8:
if (Cflag3==1)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
Cbuffer[0]='\0';
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
}
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
strcpy(Cbuf,"8");
strcat(Cbuffer,Cbuf);
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
Cflag3=0;
return 0;
case IDC_CBUTTON9:
if (Cflag3==1)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
Cbuffer[0]='\0';
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
}
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
strcpy(Cbuf,"9");
strcat(Cbuffer,Cbuf);
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
Cflag3=0;
return 0;
case IDC_CBUTTON0:
if (Cflag3==1)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
Cbuffer[0]='\0';
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
}
if(strcmp(Cbuff,Ctemp4)!=0)
{
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
strcpy(Cbuf,"0");
strcat(Cbuffer,Cbuf);
SetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer);
Cflag3=0;
}
return 0;
case IDC_CBUTTON_POINT:
if(Cflag1==0)
{
Cflag1=1;
GetWindowText(GetDlgItem(Chcwd,IDC_CEDIT),Cbuffer,CMAX1);
if(Cbuffer[0]=='\0')
{
strcpy(Cbuf,"0");
strcat(Cbuffer,Cbuf);
}
strcpy(Cbuf,".");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -