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

📄 dialog_baseddlg.cpp

📁 一个完整的计算器的例子
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
}

void CDialog_basedDlg::Oninv() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_inv=1;
	m_control_e.SetFocus();
    
    m_control_e.SetSel(0,-1);


	
}

void CDialog_basedDlg::OnHp() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_hp=1;
	
}


void CDialog_basedDlg::Onclear() 
{
	// TODO: Add your control notification handler code here

	m_op1 = 0.0;
	m_op2 = 0.0;
	m_result = 0.0;
	m_operation =0;
		
	m_num = 0.0;
	m_inv = FALSE;
	m_hp = FALSE;
	UpdateData(FALSE);
	m_control_e.SetFocus();
    st1=st2=0;
    
}

void CDialog_basedDlg::Onmul() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	m_op1 = m_num;
	m_operation = 4;
    m_control_e.SetFocus();
    st1=0;
  
	
}

void CDialog_basedDlg::Onfactoriel() 
{
	// TODO: Add your control notification handler code here
     UpdateData(TRUE);
	m_op1 = m_num;
	double tahir=m_op1;
	if(m_op1==0)
		m_num=1;
	else
	{
	while(tahir>1)
	{
		tahir--;
		m_op1=m_op1*tahir;
		
	}
	m_num=m_op1;
	}
 UpdateData(FALSE);
 m_control_e.SetFocus();
    st1=0;
   
	
}

void CDialog_basedDlg::OnM() 
{
	// TODO: Add your control notification handler code here
	 UpdateData(TRUE);
     m_m=m_num;
	 //m_num=NULL;
	UpdateData(FALSE);
	m_control_e.SetFocus();
    st1=0;
    m_control_e.SetSel(0,-1);
	
}

void CDialog_basedDlg::OnMm() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_m=m_m+m_num;
	m_num=NULL;
	UpdateData(FALSE);
	m_control_e.SetFocus();
    st1=0;
    
}

void CDialog_basedDlg::OnMr() 
{
	// TODO: Add your control notification handler code here
	m_num=m_m;
    UpdateData(FALSE);
	m_control_e.SetFocus();
    st1=0;
    m_control_e.SetSel(0,-1);
}

void CDialog_basedDlg::Onpow() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	m_op1 = m_num;
	m_operation = 5;


	m_control_e.SetFocus();
    st1=0;
    m_control_e.SetSel(0,-1);
	
}

void CDialog_basedDlg::Onx2() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	m_num=pow(m_num,2);
	UpdateData(FALSE);
	m_control_e.SetFocus();
    st1=0;
    m_control_e.SetSel(0,-1);
	
}

void CDialog_basedDlg::Onx3() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_num=pow(m_num,3);
	UpdateData(FALSE);
	m_control_e.SetFocus();
    st1=0;
    m_control_e.SetSel(0,-1);
}

void CDialog_basedDlg::Onpi() 
{
	// TODO: Add your control notification handler code here
	m_num=3.1415926535897932384626433832795;
    UpdateData(FALSE);
	m_control_e.SetFocus();
    st1=0;
   // m_control_e.SetSel(0,-1);
	
}

void CDialog_basedDlg::OnMc() 
{
	// TODO: Add your control notification handler code here
	m_m=0;
	m_control_e.SetFocus();
    st1=0;
    m_control_e.SetSel(0,-1);
	i=0;
	s=0;
	r=0;
}

void CDialog_basedDlg::OnChangeEdit1() 
{
/*	UINT nChar;
	UINT nRepCnt;
	UINT nFlags ;*/
//GetDlgItem(IDC_EDIT1)->OnChar(GetDlgItem(IDC_EDIT1)->nChar,  GetDlgItem(IDC_EDIT1)->nRepCnt,  GetDlgItem(IDC_EDIT1)->nFlags )
{
/*	switch (nChar)
	{
	case 43:
		AfxMessageBox(" Plus Pressed");
		break;
	}*/
}
}
	
void CDialog_basedDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
GetDlgItem(IDD_DIALOG_BASED_DIALOG)->EnableWindow(FALSE);

}



void CDialog_basedDlg::AddDigit(char numKey) 
{
	// TODO: Add your control notification handler code here
	CString str, tmp;

	tmp.Format("%c", numKey);
	m_control_e.GetWindowText(str);
	if(str == '0'||st1==0)
		str = tmp;
	else
		str += tmp;
	st1=1;
	m_control_e.SetWindowText(str);
}

void CDialog_basedDlg::Onclear2() 
{
	// TODO: Add your control notification handler code here
	m_num = 0;
	UpdateData(FALSE);
	st1=0;
}

void CDialog_basedDlg::Onb1() 
{
	// TODO: Add your control notification handler code here
	AddDigit('1');
}

void CDialog_basedDlg::Onb2() 
{
	// TODO: Add your control notification handler code here
	AddDigit('2');
}

void CDialog_basedDlg::Onb3() 
{
	// TODO: Add your control notification handler code here
	AddDigit('3');
}

void CDialog_basedDlg::Onb4() 
{
	// TODO: Add your control notification handler code here
	AddDigit('4');
}

void CDialog_basedDlg::Onb5() 
{
	// TODO: Add your control notification handler code here
	AddDigit('5');
}

void CDialog_basedDlg::Onb6() 
{
	// TODO: Add your control notification handler code here
	AddDigit('6');
}

void CDialog_basedDlg::Onb7() 
{
	// TODO: Add your control notification handler code here
	AddDigit('7');
}

void CDialog_basedDlg::Onb8() 
{
	// TODO: Add your control notification handler code here
	AddDigit('8');
}

void CDialog_basedDlg::Onb9() 
{
	// TODO: Add your control notification handler code here
	AddDigit('9');
}

void CDialog_basedDlg::Onb10() 
{
	// TODO: Add your control notification handler code here
	AddDigit('0');
}

void CDialog_basedDlg::Onbp() 
{
	// TODO: Add your control notification handler code here
	if(st1==0)
	AddDigit('.');
//	st1==1;
}

void CDialog_basedDlg::OnOr() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_op1 = m_num;
    m_operation= 8;
	 st1=0;
	m_control_e.SetFocus();
    
}

void CDialog_basedDlg::On1x() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_num=1/m_num;
	UpdateData(FALSE);
    st1=0;
	m_control_e.SetFocus();
    
}

void CDialog_basedDlg::Onbp2() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_num=-m_num;
	UpdateData(FALSE);
	st1=0;

}

void CDialog_basedDlg::Onst2()   //  for calculating the Averege 
{
	// TODO: Add your control notification handler code here
	
	
	m_num=r/i;
	UpdateData(FALSE);
	st1=0;
	m_control_e.SetFocus();
   
	
}

void CDialog_basedDlg::Onstat() 
{
	// TODO: Add your control notification handler code here
	i=0;
    if(s==0)
	{
	  GetDlgItem(IDC_st2)->EnableWindow(TRUE);
	   GetDlgItem(IDC_sum)->EnableWindow(TRUE);
	    GetDlgItem(IDC_s)->EnableWindow(TRUE);
		 GetDlgItem(IDC_data)->EnableWindow(TRUE);
		 s=1;
		 m_sd="SD";
		 UpdateData(FALSE);
	}
	else
	{
	 GetDlgItem(IDC_st2)->EnableWindow(FALSE);
	   GetDlgItem(IDC_sum)->EnableWindow(FALSE);
	    GetDlgItem(IDC_s)->EnableWindow(FALSE);
		 GetDlgItem(IDC_data)->EnableWindow(FALSE);
		 s=0;
		  m_sd="";
		 UpdateData(FALSE);
	}m_control_e.SetFocus();
    st1=0;
    m_control_e.SetSel(0,-1);
}

void CDialog_basedDlg::Ondata() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	data[i]=m_num;
   r  = r+data[i];
   p=p+data[i]*data[i];
	i++;
	st1=0;
	m_control_e.SetFocus();
   
}

void CDialog_basedDlg::Onsum() 
{
	// TODO: Add your control notification handler code here
	
	m_num=r;
	UpdateData(FALSE);

	st1=0;
	m_control_e.SetFocus();
   
	
}

void CDialog_basedDlg::Ons() 
{
	// TODO: Add your control notification handler code here
	
	m_num=pow((p/i-((r*r)/(i*i))),0.5);
    UpdateData(FALSE);
	st1=0;
	m_control_e.SetFocus();
    
}

void CDialog_basedDlg::OnDate() 
{
	// TODO: Add your control notification handler code here
	Ctahir t;
	t.DoModal();
}

void CDialog_basedDlg::Onroot() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_num=pow(m_num,.5);
    UpdateData(FALSE);
}

void CDialog_basedDlg::Onroot2() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_op1 = m_num;
	m_operation = 7;

    m_control_e.SetFocus();
    st1=0;
   
}
 

void CDialog_basedDlg::Onbsp() 
{
	// TODO: Add your control notification handler code here
	CString str, tmp;

	//tmp.Format("%c", numKey);
	m_control_e.GetWindowText(str);
    int a;
	a=str.GetLength();
	if(a!=0)
    str.Delete(a-1,1);

	m_control_e.SetWindowText(str);
}

void CDialog_basedDlg::OnAnd() 
{
	// TODO: Add your control notification handler code here
		UpdateData(TRUE);
	m_op1 = m_num;
    m_operation= 9;
	 st1=0;
	m_control_e.SetFocus();
    m_control_e.SetSel(0,-1);
}

void CDialog_basedDlg::OnXor() 
{
	// TODO: Add your control notification handler code here
		UpdateData(TRUE);
	m_op1 = m_num;
    m_operation= 10;
	 st1=0;
	m_control_e.SetFocus();
    m_control_e.SetSel(0,-1);
}

void CDialog_basedDlg::OnMOd() 
{
	// TODO: Add your control notification handler code here
		UpdateData(TRUE);
	m_op1 = m_num;
    m_operation= 11;
	 st1=0;
	m_control_e.SetFocus();
    m_control_e.SetSel(0,-1);
}

void CDialog_basedDlg::OnNOt() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_op1 = m_num;
    m_operation= 12;
	 st1=0;
	m_control_e.SetFocus();
    m_control_e.SetSel(0,-1);
}

⌨️ 快捷键说明

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