?? dialog_slidercolor.c
字號(hào):
/*
*********************************************************************************************************
* uC/GUI
* Universal graphic software for embedded applications
*
* (c) Copyright 2002, Micrium Inc., Weston, FL
* (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
*
* 礐/GUI is protected by international copyright laws. Knowledge of the
* source code may not be used to write a similar product. This file may
* only be used in accordance with a license and should not be redistributed
* in any way. We appreciate your understanding and fairness.
*
----------------------------------------------------------------------
File : Dialog_All.c
Purpose : Example demonstrating DIALOG and widgets
----------------------------------------------------------------------
*/
#include <stddef.h>
#include "GUI.h"
#include "DIALOG.h"
//#include "DROPDOWN.h"
/*********************************************************************
*
* static data
*
**********************************************************************
*/
#define idBtn 1000
static char strBtn[40][7]={ "tanh","cosh" ,"sin","cos" ,
"[" ,"sinh" ,"tg" ,"ctg" ,
"]" ,"ln" ,"^","lg" ,
"!" ,"arcsin","e^","sqrt",
"x" ,"arcos","pi" ,"e" ,
"off" ,"(" ,")" ,"back" ,
"7" ,"8" ,"9" ,"+" ,
"4" ,"5" ,"6" ,"-" ,
"1" ,"2" ,"3" ,"*" ,
"0" ,"." ,"=" ,"/"
};
BUTTON_Handle ahButton[52];
BUTTON_Handle hBtn[40];
EDIT_Handle hEdit;
//////////////////////////////////////////////////////////////////////
#include <MATH.H>
#include <STRING.H>
//#include <iostream.h>
#include <stdlib.h>
#define pi 3.1415926535897932384626433832795
#ifndef NULL
#define NULL 0
#endif
struct strData
{
int nCharDouble;
char cChar;
double dDouble;
struct strData *next;
struct strData *before;
} ;
struct strData *head, *temp, *pnew;//定義結(jié)構(gòu)體的一個(gè)頭結(jié)點(diǎn),一個(gè)中間變動(dòng)的結(jié)點(diǎn),一個(gè)用以申請(qǐng)的臨時(shí)結(jié)點(diǎn)
char str[100];//存要處理的字符串;
struct strData *phead, *p;//定義一個(gè)頭指針和一個(gè)移動(dòng)的指針
struct strData mydata[1024];
void Start_StrToUnionClass(char *Char);//構(gòu)造函數(shù)
void Kill_StrToUnionClass();//析構(gòu)函數(shù)
void translate_char(); //把要處理的字符串轉(zhuǎn)化為結(jié)構(gòu)體
void insert(struct strData *insert_befor , struct strData *insert_new);//用于結(jié)構(gòu)體的插入操作
void amend(); //修正得到的結(jié)構(gòu)體,如4(3+1)-->4*(3+1) , sin7-->sin(7),提高程序的應(yīng)用性
char check(char *funcName);//把常用的數(shù)學(xué)函數(shù)用一個(gè)大寫字母表示 如sin 為 H ,sqrt 為 S;
double longNum(char *c,int tag,int bit);//把處理的字符串中的表示數(shù)字的字符化為double 型
//////////////////////
void doubletochar(char outchar[],double ind)
{
char mychar[10]={'0','1','2','3','4','5','6','7','8','9'};
int i=0;
char tmp[255];
int tempi=0;
int ini;
double xiao;
if(ind<0)
{
outchar[0]='-';
ind=-ind;
i=1;
}
ini=ind;
xiao=ind-ini;
while(ini)
{
int newi=(int)ini/10;
tmp[tempi]=mychar[ini-newi*10];
ini=newi;tempi++;
}
tmp[tempi]='0';tempi++;
while(tempi)
{
outchar[i++]=tmp[--tempi];
}
outchar[i++]='.';
outchar[i++]=0;
//
tempi=0;
while(tempi<5 && xiao>0.0001)
{
int newi=xiao*10;
tmp[tempi++]=mychar[newi];
xiao=xiao*10-newi;
}
tmp[tempi++]=0;
strcat(outchar,tmp);
}
//構(gòu)造函數(shù)
void Start_StrToUnionClass( char *Char )
{
strcpy(str,Char) ;
}
//析構(gòu)函數(shù)
void Kill_StrToUnionClass()
{
int i;
for(i=0 ;i<100 ;i++)
str[i]='\0' ;
}
void translate_char()
{
int i;
head = NULL ;
for(i = 0 ; i < (int)strlen(str) ;)
{
//pnew=(struct strData *)malloc(sizeof(struct strData)) ;//開辟新結(jié)點(diǎn)
pnew=&mydata[i];
///////////////////////////////結(jié)點(diǎn)初始化/////////////////////////////////
if(head == NULL) { temp = head = pnew ; temp -> before = NULL ; } //是頭結(jié)點(diǎn)
else //連結(jié)鏈表
{
pnew -> before = temp ;
temp=temp -> next = pnew ;
}
temp -> dDouble=0 ;//初值
temp -> cChar=' ' ;
temp -> next=NULL ;//它的下一個(gè)結(jié)點(diǎn)沒東西
switch( str[i] )//對(duì)具體的字符以具體的處理
{//switch
case '+' :
temp -> nCharDouble=1 ;//1表示是字符 0 是數(shù)字
temp -> cChar='+' ; //存相應(yīng)的字符
i++ ;
break ;
case '-' : temp -> nCharDouble=1 ; temp -> cChar='-' ; i++ ;break ;
case '*' : temp -> nCharDouble=1 ; temp -> cChar='*' ; i++ ;break ;
case '/' : temp -> nCharDouble=1 ; temp -> cChar='/' ; i++ ;break ;
case '!' : temp -> nCharDouble=1 ; temp -> cChar='!' ; i++ ;break ;
case '(' : temp -> nCharDouble=1 ; temp -> cChar='(' ; i++ ;break ;
case ')' : temp -> nCharDouble=1 ; temp -> cChar=')' ; i++ ;break ;
case '^' : temp -> nCharDouble=1 ; temp -> cChar='^' ; i++ ;break ;
case '[' : temp -> nCharDouble=1 ; temp -> cChar='[' ; i++ ;break ;
case ']' : temp -> nCharDouble=1 ; temp -> cChar=']' ; i++ ;break ;
case '=' : temp -> nCharDouble=1 ; temp -> cChar='=' ; i++ ;break ;
case 'e' : temp -> nCharDouble=0 ; temp -> dDouble =2.718281828 ; i++ ;break ;
case 'p' : temp -> nCharDouble=0 ; temp -> dDouble =3.1415926535897932384626433832795 ; i=i+2 ;break ;
case 'P' : temp -> nCharDouble=0 ; temp -> dDouble =3.1415926535897932384626433832795 ; i=i+2 ;break ;
default :
{
int j=0 ;
int tagdian=0;//標(biāo)記小數(shù)點(diǎn) 1 有小數(shù)點(diǎn),0 無小數(shù)點(diǎn)
int bit=0 ;//小數(shù)點(diǎn)后是幾位
char tmpNum[20] ;//存要處理的臨時(shí)字符串,如sin cos 2.334434,3343254化為一個(gè)字符 或 數(shù)字
int n;
for ( n=0 ; n < 20 ; tmpNum[n++] = '\0') ;//初始化,用處不大
//////////////處理函數(shù)字符串////////////////
if( (str[i] >= 65 && str[i] <= 90) || (str[i] >= 97 && str[i] <= 122) )//要處理的是A- -> Z or a- -> z的字符
{
temp -> nCharDouble=1 ;
while( (str[i] >= 65 && str[i] <= 90) || (str[i] >= 97 && str[i] <= 122))//把要處理的字符用數(shù)組裝起來
{
tmpNum[j++]=str[i++] ;
}
if( strcmp( tmpNum , "log" ) == 0 && str[i++] == '1' && str[i++] == '0')temp -> cChar == 'Q' ;//log10
else temp -> cChar=check(tmpNum) ;//調(diào)用函數(shù)把字符串用一個(gè)字母替換
}
if(j != 0)break ;//上面的操作用了j ,證明了輸入的是字符,可以break了
/////////////////////處理 數(shù)字 字符串////////////////////
while( str[i] >= 48 && str[i] <= 57||str[i] == '.')//要處理的是數(shù)字 0- -> 9 加小數(shù)點(diǎn).
{
if(str[i] == '.') {tagdian=1 ;i++ ;continue ;}//有小數(shù) tagdian要標(biāo)記
if(tagdian == 1) bit=bit+1 ;//有小數(shù)輸入時(shí) 當(dāng)前輸入的是第幾位小數(shù)
temp -> nCharDouble=0 ; //標(biāo)記要存的是數(shù)字
tmpNum[19]=str[i++] ;//用數(shù)組的一位存一位數(shù)字,用數(shù)組的最后一位是為了調(diào)用函數(shù)中的字符指針,用tmpNum+19也就剛好只一位了
temp -> dDouble=longNum(tmpNum+19,tagdian,bit) ;//調(diào)用函數(shù)計(jì)算數(shù)字
}
break ;
}
}//end switch
}//end for
amend();////修正得到的結(jié)構(gòu)體,如4(3+1)-->4*(3+1) , sin7-->sin(7),提高程序的應(yīng)用性
}
char check(char *funcName)
{
char compare[][7]={"sin","cos","tg","ctg","sinh","cosh","tgh","Arcsin","Arcos",
"lg","ln","sqrt",
"tan" ,"tanh","asin","arcsin","acos","arcos","arcos","log"} ;
int i;
for(i=0 ;i<19 ;i++)
if(strcmp(compare[i],funcName) == 0)//比較得要處理的字符串和數(shù)組的第幾個(gè)相同
{
switch(i)
{
case 12: return 'J' ;
case 13: return 'N' ;
case 14:
case 15: return 'O' ;
case 16:
case 17: return 'P' ;
case 18: return 'R' ;
default :
return(72+i) ;// i >= 0,i <= 12 前面幾個(gè)是有順序的
}
}
return 'R';
}
double longNum(char *c,int tag,int bit)
{
if(tag == 0) return temp -> dDouble*10+atoi(c) ;//輸入的是整數(shù)部分
else return temp -> dDouble+pow(10,-1*bit)*atoi(c) ;//輸入的是小數(shù)部分
}
void amend()
{
struct strData *pt, *ptnew;
for(pt=head;pt->next !=NULL;pt=pt->next )
{
if(pt->nCharDouble == 0/*是數(shù)字*/&&pt->next->cChar == '(')// 2(-->2*(
{
ptnew=(struct strData *)malloc(sizeof(struct strData)) ;//開辟新結(jié)點(diǎn)
ptnew->cChar ='*';ptnew->dDouble =0;ptnew->nCharDouble =1;
insert(pt,ptnew);
}
if(pt->cChar>=72&&pt->cChar<=83/*是函數(shù)*/&&pt->next->nCharDouble == 0)// sin8-->sin(8) 也是H8-->H(8)
{
ptnew=(struct strData *)malloc(sizeof(struct strData)) ;//開辟新結(jié)點(diǎn)
ptnew->cChar ='(';ptnew->dDouble =0;ptnew->nCharDouble =1;
insert(pt,ptnew);
ptnew=(struct strData *)malloc(sizeof(struct strData)) ;//開辟新結(jié)點(diǎn)
ptnew->cChar =')';ptnew->dDouble =0;ptnew->nCharDouble =1;
//cout<<pt->next->cChar << " "<<pt->next->dDouble <<endl;
insert(pt->next->next,ptnew);
}
}
}
void insert(struct strData *insert_befor , struct strData *insert_new)
{
insert_new->before =insert_befor;
insert_new->next =insert_befor->next ;
insert_befor->next->before =insert_new;
insert_befor->next=insert_new;
}
///////////////////
void Start_CountClass(struct strData *head);//構(gòu)造函數(shù)
void OnSLOVE() ;//把存有數(shù)學(xué)表達(dá)式的結(jié)構(gòu)體計(jì)算出來
void mistake(char cfun,double dkuo);//檢查是否有錯(cuò)誤,有就顯示錯(cuò)誤
void SiSlove(struct strData *left);//計(jì)算最內(nèi)層()[]中的表達(dá)式
double Fun_switch(double dkuo,char Funhuhao );//對(duì)一個(gè)函數(shù)字母轉(zhuǎn)化為函數(shù)計(jì)算 如H(3)為sin(3), S(444.44)為sqrt(444.44)
void Start_CountClass(struct strData *tmphead)
{
phead=p=tmphead ;
}
///////////////////////////////////////////////////////////////////
///// 5+(-5+(-6+55))+(454*34-5)
//// 5+(-5+49)+(454*34-5)
void OnSLOVE()
{
struct strData *fabs_left,*left ;//記下左[和(
int nadd=0, naddFabs=0 ;//標(biāo)記()[]中字符的長(zhǎng)度
double dTemp=0 ;//一個(gè)放數(shù)據(jù)的臨時(shí)地方
for( ; p-> next !=NULL ; (dTemp==0)?p=p-> next: p)
{ //for
dTemp = 0 ;
if( p-> cChar == '[') { fabs_left=p ; naddFabs=0 ; } // 記住左絕對(duì)值的指針,naddFabs記下[]中的長(zhǎng)度
if( p-> cChar == '(') { left=p ; nadd=0 ; } // 記住左括號(hào)的指針,記下()中的長(zhǎng)度
naddFabs++, nadd++ ;
/////////////////////////求一個(gè)最里層的括號(hào)或絕對(duì)值//////////////////////////
if(p-> cChar == ')'||p-> cChar == ']')//nadd !=0標(biāo)記了進(jìn)入這個(gè)if
{ //if1
dTemp=1 ; //dTemp=0 或不用這條語(yǔ)句,答案就不對(duì)了 why???
if(p-> cChar == ']') { nadd = naddFabs ; left = fabs_left ; } // left=fabs_left ; //長(zhǎng)度,指針 統(tǒng)一給nadd,
if(nadd>3) //sin(3) 剛好三位 即括號(hào)內(nèi)還要計(jì)算
{
SiSlove(left-> next) ; //調(diào)用函數(shù)計(jì)算最內(nèi)層()[]中的表達(dá)式
}
if(p-> cChar == ']') left -> next -> dDouble =fabs(left -> next -> dDouble ) ; //計(jì)算絕對(duì)值
///在這里為止,括號(hào)中只有一個(gè)數(shù)了
if( left -> before != NULL && left -> before -> cChar >='H' && left -> before -> cChar <= 'S') //left 的前一個(gè)cChar是一個(gè)表示函數(shù)的符號(hào)
{//if2 求函數(shù)值 把結(jié)果替換掉函數(shù)名
dTemp=Fun_switch(left -> next -> dDouble,left-> before -> cChar ) ; //求函數(shù)值
left-> before-> nCharDouble =0 ;//是一個(gè)數(shù)
left-> before-> cChar =' ' ;
left-> before-> dDouble = dTemp ;//用這些取代函數(shù)名
///去掉(*)[] 中的東西, 以下再改變指針
left-> before-> next =p-> next ;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -