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

📄 mycaldlg.cpp

📁 WinCE4.2下的计算器,带有四则运算功能.evc编码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// mycalDlg.cpp : implementation file
//

#include "stdafx.h"
#include "mycal.h"
#include "mycalDlg.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "CalExpression.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif



/////////////////////////////////////////////////////////////////////////////
// CMycalDlg dialog

CMycalDlg::CMycalDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMycalDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMycalDlg)
		// NOTE: the ClassWizard will add member initialization here
	m_strResult = _T("");
	m_strExpression = _T("");
	m_display = 0.0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMycalDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMycalDlg)
	DDX_Control(pDX, IDC_RADIO1, m_radio1);
	DDX_Control(pDX, IDC_RADIO2, m_radio2);
	DDX_Control(pDX, IDC_EDIT1, m_edit1);
	DDX_Control(pDX, IDC_BUTTONEQUAL2, m_controlEqual);
	DDX_Control(pDX, IDC_EDIT_TEST, m_test);
	DDX_Control(pDX, IDC_EDIT_RESULT, m_result);
	DDX_Text(pDX, IDC_EDIT_RESULT, m_strResult);
	DDX_Text(pDX, IDC_EDIT_TEST, m_strExpression);
	DDX_Text(pDX, IDC_EDIT1, m_display);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMycalDlg, CDialog)
	//{{AFX_MSG_MAP(CMycalDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON17, OnButton17)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
	ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
	ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
	ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
	ON_BN_CLICKED(IDC_BUTTON13, OnButton13)
	ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
	ON_BN_CLICKED(IDC_BUTTON15, OnButton15)
	ON_BN_CLICKED(IDC_BUTTON16, OnButton16)
	ON_BN_CLICKED(IDC_BUTTON18, OnButton18)
	ON_BN_CLICKED(IDC_BUTTON19, OnButton19)
	ON_BN_CLICKED(IDC_BUTTON20, OnButton20)
	ON_BN_CLICKED(IDC_BUTTON21, OnButton21)
	ON_BN_CLICKED(IDC_BUTTON22, OnButton22)
	ON_BN_CLICKED(IDC_BUTTON23, OnButton23)
	ON_BN_CLICKED(IDC_BUTTON24, OnButton24)
	ON_BN_CLICKED(IDC_BUTTON28, OnButton28)
	ON_BN_CLICKED(IDC_BUTTON25, OnButton25)
	ON_BN_CLICKED(IDC_BUTTON26, OnButton26)
	ON_BN_CLICKED(IDC_BUTTON27, OnButton27)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_BUTTONEQUAL2, OnButtonequal2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMycalDlg message handlers

BOOL CMycalDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
//	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
//	ASSERT(IDM_ABOUTBOX < 0xF000);
    m_change=false;
	m_key=false;
	m_sign=true;
	m_dia=true;
	m_bit2=0;
	m_bit=0;
	m_base=0.0;
	m_middle=0.0;
	m_end=0.0;
	m_intDot=0;
	m_dot=false;

	( (CButton*)GetDlgItem(IDC_RADIO2))->SetCheck(TRUE);
	( (CButton*)GetDlgItem(IDC_RADIO4))->SetCheck(TRUE);


	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMycalDlg::OnSysCommand(UINT nID, LPARAM lParam)
{

}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMycalDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

	//	SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMycalDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}





void CMycalDlg::change()
{
	//MessageBox(_T("shit!"));
	static CRect rectLarge;
	static CRect rectSmall;

		CRect rectSeparator;

		GetWindowRect(&rectLarge);

		//GetDlgItem(IDC_STATIC)->GetWindowRect(&rectSeparator);


	//	MessageBox(_T("shit!"));
		//rectSmall.left=rectLarge.left;
	//	rectSmall.top=rectLarge.top;
	//	rectSmall.right=rectSeparator.right;
	//	rectSmall.bottom=rectLarge.bottom;
		//MessageBox(rectSmall.bottom);
	

if(m_change==true)
	{
		SetWindowPos(NULL,0,0,390,330,
			SWP_NOMOVE | SWP_NOZORDER);
	}
	else
	{
		SetWindowPos(NULL,0,0,580,330,
			SWP_NOMOVE | SWP_NOZORDER);
	}
}





void CMycalDlg::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	m_dia=false;
}

void CMycalDlg::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	m_dia=true;
}

void CMycalDlg::OnRadio4() 
{
	// TODO: Add your control notification handler code here
	m_edit1.ShowWindow(1);
	m_radio1.ShowWindow(1);
	m_radio2.ShowWindow(1);
	m_controlEqual.ShowWindow(0);
    m_test.ShowWindow(0);
	m_result.ShowWindow(0);
	m_change=false;
	change();
}

void CMycalDlg::OnRadio5() 
{
	// TODO: Add your control notification handler code here

	m_edit1.ShowWindow(1);
	m_radio1.ShowWindow(1);
	m_radio2.ShowWindow(1);
	m_controlEqual.ShowWindow(0);
    m_test.ShowWindow(0);
	m_result.ShowWindow(0);	m_change=true;
	change();
}

void CMycalDlg::Result()
{

	int i=0,j=1;
switch(m_bit)
	 {
	 case 1://"+"
		 m_base+=m_end;
		 break;
	 case 2://"-"
		 m_base-=m_end;
		 break;
	 case 3://"*"
		 if(m_bit2==0) {m_base*=m_end;
	
		 }
		 else if(m_bit2==1)m_base+=m_middle*m_end;
		 else if(m_bit2==2)m_base-=m_middle*m_end;
		 break;
	 case 4://"/"
		 if(m_end==0)
		 {
		 MessageBox(_T("除数为0!"));
		 OnButton17();
		 return;
		 }
		  if(m_bit2==0) m_base/=m_end;
		 else if(m_bit2==1)m_base+=m_middle/m_end;
		 else if(m_bit2==2)m_base-=m_middle/m_end;
		 
		 break;
	 case 5:
			 m_base=log(m_base);
			 break;
	 case 6:
			 m_base=log10(m_base);
			 break;
     case 7:
		 	if (!m_dia) m_base=m_base*3.1415926/180;
			 m_base=tan(m_base);
			 break;

	 case 8:
			 if(m_base==0)
		 {
		 MessageBox(_T("除数为0!"));
		m_display=0;
		m_end=0;
		m_bit=0;
		m_base=m_middle=0;
		m_intDot=0;
		m_dot=false;
		UpdateData(FALSE);
		 return;
			 }else{
			 m_base=1/m_base;
			 
			 }
			 break;

	 case 9:if(m_base<0)
		 {
		 MessageBox(_T("不能小于0!"));
		m_display=0;
		m_end=0;
		m_bit=0;
		m_base=m_middle=0;
		m_intDot=0;
		m_dot=false;
		UpdateData(FALSE);
		 return;
		 }
	     m_base=fun(m_base);
		 break;	 
	 	 
	 case 10:
		if (!m_dia) m_base=m_base*3.1415926/180;
		 m_base=sin(m_base);
		 break;
		 
	 case 11:
		 if (!m_dia) m_base=m_base*3.1415926/180;
		 m_base=cos(m_base);
		 break;
	 case 12:
		 m_base=sqrt(m_base);
		 break;
	 case 13:
		 m_base=exp(m_base);
		 break;
	 case 14:
		 for(i=0;i<m_base;i++)
			 j=j*10;
		 m_base=j;

		 break;
	 default:
		 m_base=m_end;
		 break;
}
	 m_bit=0;
	 m_bit2=0;
	 m_end=0;
	 m_display=m_base;
	 UpdateData(FALSE);
}


void CMycalDlg::Record()
{
 switch(m_bit)
	 {
	 case 1:
		 m_middle=m_end;
		 m_bit2=1;
		 break;
	 case 2:
		 m_middle=m_end;
		 m_bit2=2;
		 break;
	 case 3:
		 m_base*=m_end;
		
		
		 m_bit2=0;
		 break;
	 case 4:
		 if(m_end==0)
		 {
		 MessageBox(_T("除数为0!"));
			m_display=0;
		m_end=0;
		m_bit=0;
		m_base=m_middle=0;
		m_intDot=0;
		m_dot=false;
		UpdateData(FALSE);
		 return;
		 }
		 m_base/=m_end;
		 m_bit2=0;
		 break;
	 default:
		 m_base=m_end;
		 break;
	 }

	 m_end=0;
	 if(!m_bit2){
	 m_display=m_base;
	 UpdateData(FALSE);
	 }
}


void CMycalDlg::OnButton1() 
{
	// 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;
	    double temp_end;
	for(int i=1;i<=m_intDot;i++)temp=temp*10;
	temp_end=m_end;
	m_end=floor(m_end);
	//
	m_display=m_end;
		m_intDot++;
	}
	else{
	m_end=m_end*10+0;
	m_display=m_end;}

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

	UpdateData(FALSE);
}


void CMycalDlg::OnButton2() 
{
	// 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+1/temp;
	m_display=m_end;
		m_intDot++;
	}
	else{
	m_end=m_end*10+1;
	m_display=m_end;}

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

	UpdateData(FALSE);
}




void CMycalDlg::OnButton3() 
{
	// 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+2/temp;
	m_display=m_end;
		m_intDot++;
	}
	else{
	m_end=m_end*10+2;
	m_display=m_end;}

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



void CMycalDlg::OnButton4() 
{
	// 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;

⌨️ 快捷键说明

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