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

📄 calculator123dlg.cpp

📁 1、二进制、八进制、十进制及十六进制数的加、减、乘、除、乘方、取模等简单计算 2、科学计算函数
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		yingshe("e",0);
}

void CCalculator123Dlg::On15() 
{
	// TODO: Add your control notification handler code here
		yingshe("f",0);
}

void CCalculator123Dlg::Onpi() 
{
	// TODO: Add your control notification handler code here
		yingshe("PI",0);
}

void CCalculator123Dlg::One() 
{
	// TODO: Add your control notification handler code here
	yingshe("E",0);
}

void CCalculator123Dlg::Onback() 
{
	// TODO: Add your control notification handler code here
		UpdateData(1);
        yingshe("",0);
		m_pointstore.GetSel(m_nstart,m_nend);
		m_store.Delete(m_nstart-1);
		UpdateData(0);
		m_pointstore.SetFocus();
		m_pointstore.SetSel(m_nstart-1,m_nstart-1);
	
}

void CCalculator123Dlg::Onclear() 
{
	// TODO: Add your control notification handler code here
	m_store="";
	m_strRes="";
 	UpdateData(0);
	
}


	





void CCalculator123Dlg::Oncon() 
{
	// TODO: Add your control notification handler code here
 //判断是否按下常数表键,是则broad=1(默认为broad=0)
	if(!broad)   
	{
		GetWindowRect(m_rect);
    	open->SetWindowPos(NULL,m_rect.left+620,m_rect.top,-1,-1,SWP_NOSIZE);
		//括号内为设置弹出对话框的与主对话框的相对位置的参数
     	open->ShowWindow(SW_SHOW);  //发出弹出常数表对话框命令
		SetTimer(0,200,NULL);
		broad=1;
	}
	else
	{
	    open->ShowWindow(SW_HIDE);  //关闭弹出常数表对话框命令
    	broad=0;
		KillTimer(0);
	}
	
}


void CCalculator123Dlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	
	
    UpdateData(1);
	if(open->m_strN=="OVER")   //如果小键盘指针指向不为空
	{
		broad=0;
		KillTimer(0);
	}
    if(!open->m_strN.IsEmpty())
	{
		yingshe(open->m_strN,0);   //把小键盘要输入内容写到编织框
		open->m_strN="";           //然后小键盘指针附空
	}
	if(nIDEvent==3) 
	{
		GetWindowRect(m_rect);
	    open->SetWindowPos(NULL,m_rect.left+633,m_rect.top,-1,-1,SWP_NOSIZE);
	
	}
	UpdateData(0);
    CDialog::OnTimer(nIDEvent);
}

void CCalculator123Dlg::Onsin() 
{
	// TODO: Add your control notification handler code here
		yingshe("sin()",1);
}

void CCalculator123Dlg::Oncos() 
{
	// TODO: Add your control notification handler code here
		yingshe("cos()",1);
}

void CCalculator123Dlg::Ontan() 
{
	// TODO: Add your control notification handler code here
		yingshe("tan()",1);
}

void CCalculator123Dlg::Oncot() 
{
	// TODO: Add your control notification handler code here
		yingshe("cot()",1);
}

void CCalculator123Dlg::OnAsin() 
{
	// TODO: Add your control notification handler code here
		yingshe("as()",1);
}

void CCalculator123Dlg::OnAcos() 
{
	// TODO: Add your control notification handler code here
		yingshe("ac()",1);
}

void CCalculator123Dlg::OnAtan() 
{
	// TODO: Add your control notification handler code here
		yingshe("at()",1);
}

void CCalculator123Dlg::Onlog() 
{
	// TODO: Add your control notification handler code here
		yingshe("log()",1);
}

void CCalculator123Dlg::Onsh() 
{
	// TODO: Add your control notification handler code here
		yingshe("sh()",1);
}

void CCalculator123Dlg::Onch() 
{
	// TODO: Add your control notification handler code here
		yingshe("ch()",1);
}

void CCalculator123Dlg::Onth() 
{
	// TODO: Add your control notification handler code here
		yingshe("th()",1);
}

void CCalculator123Dlg::Onln() 
{
	// TODO: Add your control notification handler code here
		yingshe("ln()",1);
}

void CCalculator123Dlg::Oneee() 
{
	// TODO: Add your control notification handler code here
		yingshe("e^()",1);
}

void CCalculator123Dlg::Onsqr() 
{
	// TODO: Add your control notification handler code here
		yingshe("sqr()",1);
}

void CCalculator123Dlg::Onabs() 
{
	// TODO: Add your control notification handler code here
		yingshe("abs()",1);
}

void CCalculator123Dlg::Onexp() 
{
	// TODO: Add your control notification handler code here
		yingshe("exp()",1);
}

void CCalculator123Dlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel( );
}

void CCalculator123Dlg::OnOk() 
{
	// TODO: Add your control notification handler code here
		UpdateData(1);
		if(m_radio_degree.GetCheck()==1) calcu.m_bDegree=1;
		//制度选择如选择角度时,信息通过参数变量m_bDegree传递给运算算法
		else calcu.m_bDegree=0;
		//参数变量及时改变,确保选择弧度时结果正确

//	calcu.Dec2Hex(&m_strExp);
	CString strRes=calcu.MainPro(m_store);  //计算结果
//	m_combo_histrexp.AddString(m_strExp);
//	m_combo_histrresult.AddString(strRes);
	m_strRes=strRes;              //结果送输出框
	m_strResTmp=strRes;
    if(m_mbin.GetCheck()==1)calcu.Dec2Bin(&m_strRes);
	//把相应的10进制计算结果转换成要求的2进制数
	else if(m_moct.GetCheck()==1)calcu.Dec2Oct(&m_strRes);
     //把相应的10进制计算结果转换成要求的8进制数
    	else if(m_mhex.GetCheck()==1)calcu.Dec2Hex(&m_strRes);
      //把相应的10进制计算结果转换成要求的16进制数
   AddToHistr(m_store+"= "+strRes);    //当前计算表达式加进历史表达式中
	UpdateData(0);
//	CDialog::OnOK();
}

void CCalculator123Dlg::OnBtnBin() 
{
	// TODO: Add your control notification handler code here
	yingshe("xb",0);
	
}

void CCalculator123Dlg::OnBtnOct() 
{
	// TODO: Add your control notification handler code here
		yingshe("xo",0);
	
}

void CCalculator123Dlg::OnBtnHex() 
{
	// TODO: Add your control notification handler code here
		yingshe("xh",0);
	
}

void CCalculator123Dlg::AddToHistr(CString store)
{     //加进历史存储并显示
   int nIndex=m_ListBox.FindStringExact(-1,store);
   if(nIndex==LB_ERR)       //在历史中找不到就添进去
   {
	   nIndex=m_ListBox.AddString(store);
   }
}


void CCalculator123Dlg::OnSelchangeHistory() 
{
	// TODO: Add your control notification handler code here

    int  pos,nIndex=m_ListBox.GetCurSel();
	if(nIndex!=LB_ERR)                     //找到历史表达式
	{
	 m_ListBox.GetText(nIndex,m_str);      //找出所要找的表达式
     pos=m_str.Find("=");                  //定位"="号的位置
  	 m_store=m_str.Mid(-1,pos);            //"="前的送到输入存储参数,以传递给输入框 
	 m_strRes=m_str.Mid(pos+1,m_str.GetLength()-pos);//"="前的送到结果存储参数,以传递给输出框
	 UpdateData(FALSE);
	
}
}



void CCalculator123Dlg::Onmhex() 
{  
	// TODO: Add your control notification handler code here
	if(!m_strResTmp.IsEmpty())
	{	m_strRes=m_strResTmp;
    	calcu.Dec2Hex(&m_strRes);   //把结果参数转换成16进制数
    	if(m_strRes.Compare(".")==0) m_strRes=m_strResTmp;
	    UpdateData(0);
	}
	
else m_strRes='0';
//按键屏蔽,XXX. .EnableWindow(),XXX代表所要屏蔽的按钮的对应
//成员变量,括号内为空时不屏蔽,为FALSE 时屏蔽掉
    m_2.EnableWindow();
    m_3.EnableWindow(); 
    m_4.EnableWindow(); 
    m_5.EnableWindow();
    m_6.EnableWindow();
    m_7.EnableWindow();
    m_8.EnableWindow();
    m_9.EnableWindow();
    m_10.EnableWindow();
	m_11.EnableWindow();
	m_12.EnableWindow();
	m_13.EnableWindow();
	m_14.EnableWindow();
	m_15.EnableWindow();
	m_bin.EnableWindow(FALSE);  //2进制标识符相应屏蔽掉
    m_oct.EnableWindow(FALSE);  //8进制标识符相应屏蔽掉
    m_hex.EnableWindow();       //16进制标识符不屏蔽掉 
    //以下为函数键屏蔽
    m_sin.EnableWindow(FALSE);
	m_cos.EnableWindow(FALSE);
	m_tan.EnableWindow(FALSE);
	m_cot.EnableWindow(FALSE);
	m_arctan.EnableWindow(FALSE);
    m_arcsin.EnableWindow(FALSE);
	m_arccos.EnableWindow(FALSE);
	m_log.EnableWindow(FALSE);
	m_ln.EnableWindow(FALSE);
	m_sqr.EnableWindow(FALSE);
	m_th.EnableWindow(FALSE);
	m_sh.EnableWindow(FALSE);
	m_ch.EnableWindow(FALSE);
    m_eee.EnableWindow(FALSE);
	m_abs.EnableWindow(FALSE);
	m_exp.EnableWindow(FALSE);



	
}

void CCalculator123Dlg::Onmdec() 
{   //把结果参数转换成10进制数,不做任何结果转换操作
	// TODO: Add your control notification handler code here
		m_strRes=m_strResTmp;
	UpdateData(0); 
    m_2.EnableWindow();
    m_3.EnableWindow(); 
    m_4.EnableWindow(); 
    m_5.EnableWindow();
    m_6.EnableWindow();
    m_7.EnableWindow();
    m_8.EnableWindow();
    m_9.EnableWindow();
    m_10.EnableWindow(FALSE);
	m_11.EnableWindow(FALSE);
	m_12.EnableWindow(FALSE);
	m_13.EnableWindow(FALSE);
	m_14.EnableWindow(FALSE);
	m_15.EnableWindow(FALSE);
	m_bin.EnableWindow(FALSE);       //2进制标识符相应屏蔽掉
    m_oct.EnableWindow(FALSE);       //8进制标识符相应屏蔽掉
    m_hex.EnableWindow(FALSE);       //16进制标识符相应屏蔽掉 
   //以下为函数键恢复,即不屏蔽
	m_sin.EnableWindow();
	m_cos.EnableWindow();
	m_tan.EnableWindow();
	m_cot.EnableWindow();
	m_arctan.EnableWindow();
    m_arcsin.EnableWindow();
	m_arccos.EnableWindow();
	m_log.EnableWindow();
	m_ln.EnableWindow();
	m_sqr.EnableWindow();
	m_th.EnableWindow();
	m_sh.EnableWindow();
	m_ch.EnableWindow();
    m_eee.EnableWindow();
	m_abs.EnableWindow();
	m_exp.EnableWindow();

}

void CCalculator123Dlg::Onmoct() 
{  
	// TODO: Add your control notification handler code here
	if(!m_strResTmp.IsEmpty())
	{	m_strRes=m_strResTmp;
	    calcu.Dec2Oct(&m_strRes);   //把结果参数转换成8进制数 
		if(m_strRes.Compare(".")==0) m_strRes=m_strResTmp;
		UpdateData(0);
	}
	else m_strRes='0';
   //8进制1~7键不屏蔽
    m_2.EnableWindow();
    m_3.EnableWindow(); 
    m_4.EnableWindow(); 
    m_5.EnableWindow();
    m_6.EnableWindow();
    m_7.EnableWindow();
    //8进制8~f键屏蔽
    m_8.EnableWindow(FALSE);
    m_9.EnableWindow(FALSE);
    m_10.EnableWindow(FALSE);
	m_11.EnableWindow(FALSE);
	m_12.EnableWindow(FALSE);
	m_13.EnableWindow(FALSE);
	m_14.EnableWindow(FALSE);
	m_15.EnableWindow(FALSE);
	m_bin.EnableWindow(FALSE);
    m_oct.EnableWindow();  //8进制标识不屏蔽
    m_hex.EnableWindow(FALSE);
   //以下为函数键屏蔽
    m_sin.EnableWindow(FALSE);
	m_cos.EnableWindow(FALSE);
	m_tan.EnableWindow(FALSE);
	m_cot.EnableWindow(FALSE);
	m_arctan.EnableWindow(FALSE);
    m_arcsin.EnableWindow(FALSE);
	m_arccos.EnableWindow(FALSE);
	m_log.EnableWindow(FALSE);
	m_ln.EnableWindow(FALSE);
	m_sqr.EnableWindow(FALSE);
	m_th.EnableWindow(FALSE);
	m_sh.EnableWindow(FALSE);
	m_ch.EnableWindow(FALSE);
    m_eee.EnableWindow(FALSE);
	m_abs.EnableWindow(FALSE);
	m_exp.EnableWindow(FALSE);


}

void CCalculator123Dlg::Onmbin() 
{   
	// TODO: Add your control notification handler code here
	if(!m_strResTmp.IsEmpty())
	{	m_strRes=m_strResTmp;
		calcu.Dec2Bin(&m_strRes);   	//把结果参数转换成2进制数
		if(m_strRes.Compare(".")==0) m_strRes=m_strResTmp;
		UpdateData(0);
	}
	else m_strRes='0';
    //2进制2~f键屏蔽
    m_2.EnableWindow(FALSE);
    m_3.EnableWindow(FALSE); 
    m_4.EnableWindow(FALSE); 
    m_5.EnableWindow(FALSE);
    m_6.EnableWindow(FALSE);
    m_7.EnableWindow(FALSE);
    m_8.EnableWindow(FALSE);
    m_9.EnableWindow(FALSE);
    m_10.EnableWindow(FALSE);
	m_11.EnableWindow(FALSE);
	m_12.EnableWindow(FALSE);
	m_13.EnableWindow(FALSE);
	m_14.EnableWindow(FALSE);
	m_15.EnableWindow(FALSE);

	m_bin.EnableWindow();        //2进制标识符不屏蔽掉
    m_hex.EnableWindow(FALSE);
    m_oct.EnableWindow(FALSE);
   //以下为函数键屏蔽
    m_sin.EnableWindow(FALSE);
	m_cos.EnableWindow(FALSE);
	m_tan.EnableWindow(FALSE);
	m_cot.EnableWindow(FALSE);
	m_arctan.EnableWindow(FALSE);
    m_arcsin.EnableWindow(FALSE);
	m_arccos.EnableWindow(FALSE);
	m_log.EnableWindow(FALSE);
	m_ln.EnableWindow(FALSE);
	m_sqr.EnableWindow(FALSE);
	m_th.EnableWindow(FALSE);
	m_sh.EnableWindow(FALSE);
	m_ch.EnableWindow(FALSE);
    m_eee.EnableWindow(FALSE);
	m_abs.EnableWindow(FALSE);
	m_exp.EnableWindow(FALSE);
}

⌨️ 快捷键说明

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