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

📄 mycaldlg.cpp

📁 WinCE4.2下的计算器,带有四则运算功能.evc编码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	for(int i=1;i<=m_intDot;i++)temp=temp*10;
	m_end=m_end+3/temp;
	m_display=m_end;
		m_intDot++;
	}
	else{
	m_end=m_end*10+3;
	m_display=m_end;}

		if(m_sign==false){
		m_end=0-m_end;
		m_display=0-m_display;
	}
	UpdateData(FALSE);	
}

void CMycalDlg::OnButton5() 
{
	// TODO: Add your control notification handler code here
	if (m_key) {m_base=0;m_key=false;}
	if(m_end<0) m_end=0-m_end;
	if(m_intDot!=0){
		double temp=1;
	
	for(int i=1;i<=m_intDot;i++)temp=temp*10;
	m_end=m_end+4/temp;
	m_display=m_end;
		m_intDot++;
	}
	else{
	m_end=m_end*10+4;
	m_display=m_end;}

		if(m_sign==false){
		m_end=0-m_end;
		m_display=0-m_display;
	}
	UpdateData(FALSE);	
}

void CMycalDlg::OnButton6() 
{
	// TODO: Add your control notification handler code here
	if (m_key) {m_base=0;m_key=false;}
	if(m_end<0) m_end=0-m_end;
		if(m_intDot!=0){
		double temp=1;
	
	for(int i=1;i<=m_intDot;i++)temp=temp*10;
	m_end=m_end+5/temp;
	m_display=m_end;
		m_intDot++;
	}
	else{
	m_end=m_end*10+5;
	m_display=m_end;}

		if(m_sign==false){
		m_end=0-m_end;
		m_display=0-m_display;
	}
	UpdateData(FALSE);	
}

void CMycalDlg::OnButton7() 
{
	// TODO: Add your control notification handler code here
	if (m_key) {m_base=0;m_key=false;}
	if(m_end<0) m_end=0-m_end;
			if(m_intDot!=0){
		double temp=1;
	
	for(int i=1;i<=m_intDot;i++)temp=temp*10;
	m_end=m_end+6/temp;
	m_display=m_end;
		m_intDot++;
	}
	else{
	m_end=m_end*10+6;
	m_display=m_end;}

		if(m_sign==false){
		m_end=0-m_end;
		m_display=0-m_display;
	}
	UpdateData(FALSE);
}

void CMycalDlg::OnButton8() 
{
	// TODO: Add your control notification handler code here
	if (m_key) {m_base=0;m_key=false;}
	if(m_end<0) m_end=0-m_end;
	if(m_intDot!=0){
		double temp=1;
	
	for(int i=1;i<=m_intDot;i++)temp=temp*10;
	m_end=m_end+7/temp;
	m_display=m_end;
		m_intDot++;
	}
	else{
	m_end=m_end*10+7;
	m_display=m_end;}

		if(m_sign==false){
		m_end=0-m_end;
		m_display=0-m_display;
	}
	UpdateData(FALSE);	
}

void CMycalDlg::OnButton9() 
{
	// TODO: Add your control notification handler code here
	if (m_key) {m_base=0;m_key=false;}
	if(m_end<0) m_end=0-m_end;
		if(m_intDot!=0){
		double temp=1;
	
	for(int i=1;i<=m_intDot;i++)temp=temp*10;
	m_end=m_end+8/temp;
	m_display=m_end;
		m_intDot++;
	}
	else{
	m_end=m_end*10+8;
	m_display=m_end;}


		if(m_sign==false){
		m_end=0-m_end;
		m_display=0-m_display;
	}
	UpdateData(FALSE);	
}

void CMycalDlg::OnButton10() 
{
	// TODO: Add your control notification handler code here
	if (m_key) {m_base=0;m_key=false;}
	if(m_end<0) m_end=0-m_end;
	if(m_intDot!=0){
		double temp=1;
	
	for(int i=1;i<=m_intDot;i++)temp=temp*10;
	m_end=m_end+9/temp;
	m_display=m_end;
		m_intDot++;
	}
	else{
	m_end=m_end*10+9;
	m_display=m_end;}

		if(m_sign==false){
		m_end=0-m_end;
		m_display=0-m_display;
	}
	UpdateData(FALSE);	
}

void CMycalDlg::OnButton11() 
{
	// TODO: Add your control notification handler code here
	m_sign=!m_sign;
	m_key=false;
	m_end=0-m_end;
	m_display=m_end;
	UpdateData(FALSE);
}

void CMycalDlg::OnButton17() 
{
	// TODO: Add your control notification handler code here
	m_display=0;
	m_end=0;	
	m_intDot=0;
	m_key=false;
	m_dot=false;
	UpdateData(FALSE);
}

double CMycalDlg::fun(double i)
{



	if (i==0) return(1);  //如果从键盘上输入的数是0,则返回1,即0的阶乘为1。
		return(i*fun(i-1)); //如果从键盘上输入的数不是0,则调用它自身进行x*fun(x-1)运算并且返回该值。


}

void CMycalDlg::OnButton12() 
{
	// TODO: Add your control notification handler code here
	if(m_dot==false){
		m_key=false;
	m_intDot++;
	m_dot=true;
	}	
}

void CMycalDlg::OnButton13() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	Result();
	
	m_bit=1;	
	m_intDot=0;
	m_dot=false;	
}

void CMycalDlg::OnButton14() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	Result();
	m_bit=2;
	m_intDot=0;
	m_dot=false;	
}

void CMycalDlg::OnButton15() 
{
	// TODO: Add your control notification handler code here
	if(m_key) {m_bit=3;m_bit2=0;m_end=1;}
	m_key=false;
	Record();
	m_bit=3;
	m_intDot=0;
	m_dot=false;	
}

void CMycalDlg::OnButton16() 
{
	// TODO: Add your control notification handler code here
	if(m_key) {m_bit=4;m_bit2=0;m_end=1;}
	m_key=false;
	Record();
	m_bit=4;
	m_intDot=0;
	m_dot=false;	
}

void CMycalDlg::OnButton18() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	Result();
	m_bit=12;	
	m_intDot=0;
	m_dot=false;
	Result();
	m_key=true;
	m_end=m_base;

}

void CMycalDlg::OnButton19() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	Result();
	m_bit=8;
	m_intDot=0;
	m_dot=false;
	Result();
	m_key=true;
	m_end=m_base;
}

void CMycalDlg::OnButton20() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	m_intDot=0;
	m_dot=false;
	Result();
	m_key=true;
	m_bit=1;
	m_bit2=0;
	m_middle=0;
//	m_base=0;
	UpdateData(FALSE);
}

void CMycalDlg::OnButton21() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	Result();
	m_bit=13;
	m_intDot=0;
	m_dot=false;
	Result();
	m_key=true;
	m_end=m_base;
}

void CMycalDlg::OnButton22() 
{
	// TODO: Add your control notification handler code here
	if(m_key) goto ccc;
	m_key=false;
	Result();
ccc:	m_bit=14;
	m_intDot=0;
	m_dot=false;
	Result();
	m_key=true;

	

}

void CMycalDlg::OnButton23() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	Result();
	m_bit=11;	
	m_intDot=0;
	m_dot=false;
	Result();
	m_key=true;
	m_end=m_base;
}

void CMycalDlg::OnButton24() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	Result();
	m_bit=10;
	m_intDot=0;
	m_dot=false;
	Result();
	m_key=true;
	m_end=m_base;
}

void CMycalDlg::OnButton28() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	Result();
	m_bit=9;
	m_intDot=0;
	m_dot=false;
	Result();
		m_key=true;
	m_end=m_base;
}

void CMycalDlg::OnButton25() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	Result();
	m_bit=5;
	m_intDot=0;
	m_dot=false;
	Result();
	m_key=true;
	m_end=m_base;
}

void CMycalDlg::OnButton26() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
		Result();
	m_bit=6;
	m_intDot=0;
	m_dot=false;
	Result();
	m_key=true;
	m_end=m_base;
}

void CMycalDlg::OnButton27() 
{
	// TODO: Add your control notification handler code here
	m_key=false;
	Result();
	m_bit=7;
	m_intDot=0;
	m_dot=false;
	Result();
	m_key=true;
	m_end=m_base;
}



void CMycalDlg::OnRadio3() 
{
	// TODO: Add your control notification handler code here
	m_edit1.ShowWindow(0);
	m_radio1.ShowWindow(0);
	m_radio2.ShowWindow(0);
	m_controlEqual.EnableWindow();
	m_controlEqual.ShowWindow(1);
	m_test.ShowWindow(1);
	m_result.ShowWindow(1);
	SetWindowPos(NULL,0,0,580,145,
			SWP_NOMOVE | SWP_NOZORDER);
}

void CMycalDlg::OnButtonequal2() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CString tem = m_strExpression;
	CString Tail = "#";
	tem += Tail;
	//LPWSTR temp=(LPWSTR)tem.GetBuffer(0);
	//char* pC = (unsigned char*)(LPCTSTR)str; 
	//char* pC = (char*)(LPCTSTR)tem.GetBuffer(0);  char[]   a=dlg.ToCharArray();   

//	char *pC1=(char*)(LPCTSTR)tem.GetBuffer(tem.GetLength()+1);
	//char s[256] ; 
	//字符串复制用 
//_tcscpy( s , tem.GetBuffer(tem.GetLength()) ) ;
	/*
	int strLength = cstr1.GetLength() + 1;
    char *pValue = new char[strLength];
    strncpy(pValue, cstr1, strLength);
	CString   str=“ABC”;   
	TCHAR*   b;   
  b=(LPCTSTR)str;
 
	*/
	TCHAR *pC1=(TCHAR*)(LPCTSTR)tem.GetBuffer(tem.GetLength());
	char* pC2;
	//int strLength=tem.GetLength()+1;
	//char *pC1= new char[strLength];
	//strncpy(pC1, (char*)(LPCTSTR)strLength, strLength);

	
//	tem.ToCharArray();
//pC1=pC1+
/*	int len = WideCharToMultiByte(CP_ACP, 0, tem, -1, NULL, 0, NULL, NULL);
	
	char* szTarget = new char[len + 1];
	
	memset(szTarget, 0, len + 1);
	
     WideCharToMultiByte (CP_ACP, 0,tem, -1, szTarget, len, NULL,NULL);
	 delete[] szTarget;*/
	pC2=THCAR2char(pC1);
	 //CString ts(pC2);
	//MessageBox(ts);


	 WordAnalyse MyWords(pC2);
	if(MyWords.GetResult() == false)
	{
		MessageBox(_T("词法错误"));
		return;
	}
	//char *pC2 =(LPSTR)(LPCTSTR)tem;
//PtrToStringUni
	
	CalExpression expression(pC2,MyWords);
	int type = expression.Calculate(MyWords);
	
	
	if(expression.GetValueType()==0)
		
		m_strResult.Format(_T("%d"),expression.GetIntResult());
	
	
	if(expression.GetValueType()==1)
		m_strResult.Format(_T("%f"),expression.GetDoubleResult());
	
	if(expression.GetValueType()== -1)
		
		MessageBox(_T("语法错误"));
	UpdateData(0);
}

char* CMycalDlg::THCAR2char(TCHAR* tchStr) 
{ 
	int iLen = 2*wcslen(tchStr);//CString,TCHAR汉字算一个字符,因此不用普通计算长度 
	char* chRtn = new char[iLen+1]; 
		wcstombs(chRtn,tchStr,iLen+1);//转换成功返回为非负值 
	return chRtn; 
} 

⌨️ 快捷键说明

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