⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialog_slidercolor.c

📁 移植到嵌入式上的科学计算器
💻 C
📖 第 1 页 / 共 3 页
字号:
				  p=p-> next -> before =left-> before ;
					  		  
			  }//end if 2
			   
			  else //括号前没有函数名
			  {//else 
				  
				  left-> nCharDouble =0 ;//是一个数
				  left-> cChar =' ' ;
				  left-> dDouble = left-> next -> dDouble  ;//用这个数取代 ( or [				  
			      left-> next =p-> next  ;
				  p=p-> next -> before =left  ;			  
				 

			  }//end if
             while(p!=phead)//向前找一个 ( or [
			 {   p=p-> before ;
				 if(p-> cChar == '(' || p-> cChar == '[')break ;
			 }
		}//end if 1

		}//end for	

	SiSlove(phead) ;//把最后没有括号 的表达式再计算一下
 
}

void SiSlove(struct  strData *left)
{
    struct strData		*first ;//left 固定,first 移动	
	int					i ;
	double				add ;    

    for(first=left ;first-> cChar !=')' && first-> cChar !=']' && first-> next != NULL ;)//计算 *  /  ^  !  剩下的累加
	{
		
		switch(first-> cChar)
		 {

	       	case '^': //计算+2^3-,为+8-
		    	first-> before -> dDouble =pow(first-> before -> dDouble ,first-> next -> dDouble ) ; 
				first-> before -> next = first-> next -> next ;
				first-> next-> next  -> before = first-> before ;
				first = first-> next -> next ;
				break ;
			case '!'://计算-2!+, 为-2+
				for( i=1, add=1 ;i<=(int)first-> before -> dDouble  ;i++) add=add*i ;
				first-> before -> dDouble =add ;
				first-> before -> next =first-> next  ;
				first-> next -> before =first-> before  ;
				first=first-> next  ;
				break ;
		    case '*' : //计算 -2*5+ 为-10+ 
				 first-> before ->  dDouble =first-> before ->  dDouble * first-> next -> dDouble  ;
				 first-> before -> next =first-> next -> next  ;
				 first-> next -> next-> before =first-> before ;
				 first=first-> next -> next ;
				 break ;
            case '/' : //计算 -10/2+ 为-5+ 
	             first-> before ->  dDouble =first-> before ->  dDouble / first-> next -> dDouble  ;
				 first-> before -> next =first-> next -> next  ;
				 first-> next -> next-> before =first-> before ;
				 first=first-> next -> next ;
	             break ;
			default :
				 first=first-> next ;
				 break ;
		}
	}

	first=left ;
	if(first-> cChar == '-') //-w+32 为 q+32  q为-w  第一个是负号的处理
	{
      first-> nCharDouble =0  ;
	  first-> cChar =' ' ;
	  first-> dDouble =-1*first-> next -> dDouble  ;
	  first-> next =first-> next -> next  ;
	  first-> next -> next-> before =first ;
	}
    //计算加减
     for(first=left ;first-> cChar !=')' && first-> cChar !=']' && first-> next != NULL ;first=first-> next )//+ -
	 {
		  if(first ->  cChar == '-') left-> dDouble =left-> dDouble - first-> next -> dDouble  ;
		  if(first ->  cChar == '+') left-> dDouble =left-> dDouble + first-> next -> dDouble  ;
	 }

}



double Fun_switch(double dkuo,char Funhuhao )
{
    switch(Funhuhao)
	{
      case 'H' : return  sin(dkuo) ;  
	 case 'I' : return  cos(dkuo) ;
	 case 'J' : mistake(Funhuhao,dkuo);  return  tan(dkuo) ;
	 case 'K' : mistake(Funhuhao,dkuo);  return  1.0/tan(dkuo) ;    
	 case 'L' : return  sinh(dkuo) ; 
	 case 'M' : return  cosh(dkuo) ; 
	 case 'N' : return  tanh(dkuo) ;
	 case 'O' : mistake(Funhuhao,dkuo);  return  asin(dkuo) ;
	 case 'P' : mistake(Funhuhao,dkuo);  return  acos(dkuo) ;
	 case 'Q' : mistake(Funhuhao,dkuo);  return  log10(dkuo) ;
	 case 'R' : mistake(Funhuhao,dkuo);  return  log(dkuo) ;
	 case 'S' : mistake(Funhuhao,dkuo);  return  sqrt(dkuo) ;  
	}
	   return 'S';
}

void mistake(char cfun,double dkuo)
{
//	cout<< "text error";
	double dfun=dkuo;
	switch(cfun)
	{
	case 'J' :  if(fabs(dfun/pi-(long)(dfun/pi)-0.5)<=0.0000000001) 
		//::AfxMessageBox("error  : tg的定义不对,x!=π/2±k*π,k∈Z,请检查!!");
		break;// dkou/pi是0.5 1.5 2.5 
	case 'K' : if(fabs(dfun/pi-(long)(dfun/pi))<=0.0000000001) 
		//::AfxMessageBox("error  : ctg的定义不对,x!=k*π,k∈Z,请检查!!");
		break;// dkou/pi是0 1.0 2.0
	case 'O' :if(fabs(dfun)>1) 
		//::AfxMessageBox("error  : asin的定义大于1,不对,请检查!!");
		break;//
	case 'P' :if(fabs(dfun)>1) 
		//::AfxMessageBox("error  : acos的定义大于1,不对-1<x<1,请检查!!");
		break;//
	case 'Q' :if(dfun<0) 
		//::AfxMessageBox("error  : lg的定义小于0,不对 x>0,请检查!!");
		break;//
	case 'R' :if(dfun<0) 
		//::AfxMessageBox("error  : log的定义小于0,不对 x>0,请检查!!");
		break;//
	case 'S' :if(dfun<0) 
		//::AfxMessageBox("error  : sqrt的定义小于0,不对 x>0,请检查!!");
		break;//
	}

	

}
//////////////////////////////////////////////////////////////////////
void MyProcess(int Key)
{
	char cBuf[1024];
	int index=Key-idBtn;
	int nlen;
	if(index<0 || index>=40)
		return;	
#ifdef MYMUL
	switch(index) 
	{
	case 23:
		MULTIEDIT_GetText(hEdit,cBuf,1024);
		nlen=strlen(cBuf);
		if (nlen) {
			cBuf[nlen-1]=0;
			MULTIEDIT_SetText(hEdit,cBuf);
		}		
		break;
	case 20:
		cBuf[0]=0;
		MULTIEDIT_SetText(hEdit,cBuf);
		break;
	case 38:
		{
			char char_result[1024];
			MULTIEDIT_GetText(hEdit,cBuf,1024);
			strcat(cBuf,"=");
			Start_StrToUnionClass( cBuf) ;
			translate_char(); 
			Start_CountClass(head);
			OnSLOVE() ; 
			//_gcvt( head->dDouble,10, char_result);	 
			//sprintf(char_result,"%.3f",head->dDouble);
			doubletochar(char_result,head->dDouble);
			strcat(cBuf,char_result);
			MULTIEDIT_SetText(hEdit,cBuf);
			Kill_StrToUnionClass();
		}		
		break;
	default:
		MULTIEDIT_GetText(hEdit,cBuf,1024);
		strcat(cBuf,strBtn[index]);
		MULTIEDIT_SetText(hEdit,cBuf);
	}
#else
	switch(index) 
	{
	case 23:
		EDIT_GetText(hEdit,cBuf,1024);
		nlen=strlen(cBuf);
		if (nlen) {
			cBuf[nlen-1]=0;
			EDIT_SetText(hEdit,cBuf);
		}		
		break;
	case 20:
		cBuf[0]=0;
		EDIT_SetText(hEdit,cBuf);
		break;
	case 38:
		{
			char char_result[1024];
			EDIT_GetText(hEdit,cBuf,1024);
			strcat(cBuf,"=");
			Start_StrToUnionClass( cBuf) ;
			translate_char(); 
			Start_CountClass(head);
			OnSLOVE() ; 
			//_gcvt( head->dDouble,10, char_result);	 
			//sprintf(char_result,"%.3f",head->dDouble);
			doubletochar(char_result,head->dDouble);
			strcat(cBuf,char_result);
			EDIT_SetText(hEdit,cBuf);
			Kill_StrToUnionClass();
		}		
		break;
	default:
		EDIT_GetText(hEdit,cBuf,1024);
		strcat(cBuf,strBtn[index]);
		EDIT_SetText(hEdit,cBuf);
	}
#endif
	
}
/*********************************************************************
*
*       Dialog resource
*
* This table conatins the info required to create the dialog.
* It has been created manually, but could also be created by a GUI-builder.
*/
/*
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Dialog", 0,                 30,   5, 260, 230, FRAMEWIN_CF_MOVEABLE, 0  },
  { BUTTON_CreateIndirect,   "OK",     GUI_ID_OK,        100,   5,  60,  20 },
  { BUTTON_CreateIndirect,   "Cancel", GUI_ID_CANCEL,    100,  30,  60,  20 },
  { TEXT_CreateIndirect,     "LText",  0,                 10,  55,  48,  15, TEXT_CF_LEFT  },
  { TEXT_CreateIndirect,     "RText",  0,                 10,  80,  48,  15, TEXT_CF_RIGHT },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT0,      60,  55, 100,  15, 0, 50 },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT1,      60,  80, 100,  15, 0, 50 },
  { TEXT_CreateIndirect,     "Hex",    0,                 10, 100,  48,  15, TEXT_CF_RIGHT },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT2,      60, 100, 100,  15, 0, 6 },
  { TEXT_CreateIndirect,     "Bin",    0,                 10, 120,  48,  15, TEXT_CF_RIGHT },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT3,      60, 120, 100,  15 },
  { LISTBOX_CreateIndirect,  NULL,     GUI_ID_LISTBOX0,   10,  10,  60,  40 },
  { CHECKBOX_CreateIndirect, NULL,     GUI_ID_CHECK0,     10, 140,   0,   0 },
  { CHECKBOX_CreateIndirect, NULL,     GUI_ID_CHECK1,     30, 140,   0,   0 },
  { SLIDER_CreateIndirect,   NULL,     GUI_ID_SLIDER0,    60, 140, 180,  20 },
  { SLIDER_CreateIndirect,   NULL,     GUI_ID_SLIDER1,    10, 170, 230,  30 },
  { DROPDOWN_CreateIndirect,  NULL,    GUI_ID_DROPDOWN0, 170,  10,  80,  60, 0, 3  },
  { DROPDOWN_CreateIndirect,  NULL,    GUI_ID_DROPDOWN1, 170,  60,  80,  60, 0, 3  }
};
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Dialog", 0,                 5,   5, 260, 260, FRAMEWIN_CF_MOVEABLE, 0  },
  //{ BUTTON_CreateIndirect,   "OK",     GUI_ID_OK,        100,   5,  60,  20 },
  //{ BUTTON_CreateIndirect,   "Cancel", GUI_ID_CANCEL,    100,  30,  60,  20 },
  //
  { BUTTON_CreateIndirect,   "OK",     idBtn,        100,   5,    30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+1,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+2,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+3,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+4,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+5,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+6,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+7,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+8,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+9,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+10,        100,   5,  30,  30 },
  //
  { BUTTON_CreateIndirect,   "OK",     idBtn+11,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+12,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+13,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+14,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+15,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+16,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+17,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+18,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+19,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+20,        100,   5,  30,  30 },
  // 25,  25 }, 30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+21,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+22,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+23,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+24,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+25,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+26,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+27,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+28,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+29,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+30,        100,   5,  30,  30 },
  // 25,  25 }, 30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+31,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+32,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+33,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+34,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+35,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+36,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+37,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+38,        100,   5,  30,  30 },
  { BUTTON_CreateIndirect,   "OK",     idBtn+39,        100,   5,  30,  30 }
  /*25,  25 },30,  30 },
  { TEXT_CreateIndirect,     "LText",  0,                 10,  55,  30,  30 }, 25,  25 }, 48,  15, TEXT_CF_LEFT  },
  { TEXT_CreateIndirect,     "RText",  0,                 10,  80,  48,  15, TEXT_CF_RIGHT },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT0,      60,  55, 100,  15, 0, 50 },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT1,      60,  80, 100,  15, 0, 50 },
  { TEXT_CreateIndirect,     "Hex",    0,                 10, 100,  48,  15, TEXT_CF_RIGHT },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT2,      60, 100, 100,  15, 0, 6 },
  { TEXT_CreateIndirect,     "Bin",    0,                 10, 120,  48,  15, TEXT_CF_RIGHT },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT3,      60, 120, 100,  15 },
  { LISTBOX_CreateIndirect,  NULL,     GUI_ID_LISTBOX0,   10,  10,  60,  40 },
  { CHECKBOX_CreateIndirect, NULL,     GUI_ID_CHECK0,     10, 140,   0,   0 },
  { CHECKBOX_CreateIndirect, NULL,     GUI_ID_CHECK1,     30, 140,   0,   0 },
  { SLIDER_CreateIndirect,   NULL,     GUI_ID_SLIDER0,    60, 140, 180,  20 },
  { SLIDER_CreateIndirect,   NULL,     GUI_ID_SLIDER1,    10, 170, 230,  30 },
  { DROPDOWN_CreateIndirect,  NULL,    GUI_ID_DROPDOWN0, 170,  10,  80,  60, 0, 3  },
  { DROPDOWN_CreateIndirect,  NULL,    GUI_ID_DROPDOWN1, 170,  60,  80,  60, 0, 3  }
  */
};
/*********************************************************************
*
*              Initializers for listbox
*/
static const GUI_ConstString _apListBox[] = {
  "English", "Deutsch", "Fran鏰is", "Japanese", "Italiano", NULL
};

/*******************************************************************
*
*       static code
*
********************************************************************
*/

/*********************************************************************
*
*       _cbBkWindow
*/
static void _cbBkWindow(WM_MESSAGE* pMsg) {
  switch (pMsg->MsgId) {
  case WM_PAINT:
    GUI_SetBkColor(GUI_RED);
    GUI_Clear();
    GUI_SetColor(GUI_WHITE);
    GUI_SetFont(&GUI_Font24_ASCII);
    GUI_DispStringHCenterAt("DIALOG_All - Sample", 160, 5);
    break;
  default:
    WM_DefaultProc(pMsg);
  }
}

/*********************************************************************
*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -