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

📄 计算器dlg.cpp

📁 加减乘除计算,正余弦,倒数,阶乘计算,进制转换等
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// 计算器Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "计算器.h"
#include "计算器Dlg.h"
#include "stdlib.h"
#include "math.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define E 2.7182818284590452353
double pi=3.1415926535897932384626433832795;
int  i,j,h=0,t=1;
double n1,n2,n3,n4;
char  s;
int k;
char str1[30];
struct string
{char str2[50];
}str3[15];

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
	m_strResult = _T("");
	m_lishi = _T("");
	m_shi = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
	DDX_Text(pDX, IDC_EDIT_RESULT, m_strResult);
	DDV_MaxChars(pDX, m_strResult, 100);
	DDX_Text(pDX, IDC_LISHI, m_lishi);
	DDX_Text(pDX, IDC_SHI, m_shi);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_Num_0, OnNum0)
	ON_BN_CLICKED(IDC_Num_2, OnNum2)
	ON_BN_CLICKED(IDC_FUHAO, OnFuhao)
	ON_BN_CLICKED(IDC_Num_1, OnNum1)
	ON_BN_CLICKED(IDC_Num_3, OnNum3)
	ON_BN_CLICKED(IDC_Num_4, OnNum4)
	ON_BN_CLICKED(IDC_Num_5, OnNum5)
	ON_BN_CLICKED(IDC_NUM_6, OnNum6)
	ON_BN_CLICKED(IDC_Num_7, OnNum7)
	ON_BN_CLICKED(IDC_Num_8, OnNum8)
	ON_BN_CLICKED(IDC_Num_9, OnNum9)
	ON_BN_CLICKED(IDC_Num_10, OnNum10)
	ON_BN_CLICKED(IDC_Num_11, OnNum11)
	ON_BN_CLICKED(IDC_Num_12, OnNum12)
	ON_BN_CLICKED(IDC_Num_13, OnNum13)
	ON_BN_CLICKED(IDC_Num_14, OnNum14)
	ON_BN_CLICKED(IDC_Num_15, OnNum15)
	ON_BN_CLICKED(IDC_DOT, OnDot)
	ON_BN_CLICKED(IDC_AC, OnAc)
	ON_BN_CLICKED(IDC_Back, OnBack)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_Equal, OnEqual)
	ON_BN_CLICKED(IDC_DEC, OnDec)
	ON_BN_CLICKED(IDC_MUT, OnMut)
	ON_BN_CLICKED(IDC_DIV, OnDiv)
	ON_BN_CLICKED(IDC_MO, OnMo)
	ON_BN_CLICKED(IDC_MUTMUT, OnMutmut)
	ON_BN_CLICKED(IDC_SIN, OnSin)
	ON_BN_CLICKED(IDC_COS, OnCos)
	ON_BN_CLICKED(IDC_TAN, OnTan)
	ON_BN_CLICKED(IDC_COT, OnCot)
	ON_BN_CLICKED(IDC_LN, OnLn)
	ON_BN_CLICKED(IDC_LOG, OnLog)
	ON_BN_CLICKED(IDC_DECIMALIST, OnDecimalist)
	ON_BN_CLICKED(IDC_HEX, OnHex)
	ON_BN_CLICKED(IDC_OCTAL, OnOctal)
	ON_BN_CLICKED(IDC_BINARY, OnBinary)
	ON_BN_CLICKED(IDC_DEGREE, OnDegree)
	ON_BN_CLICKED(IDC_RADIAN, OnRadian)
	ON_BN_CLICKED(IDC_ASIN, OnAsin)
	ON_BN_CLICKED(IDC_ACOS, OnAcos)
	ON_BN_CLICKED(IDC_ATAN, OnAtan)
	ON_BN_CLICKED(IDC_ACOT, OnAcot)
	ON_BN_CLICKED(IDC_EXP, OnExp)
	ON_BN_CLICKED(IDC_DAOSHU, OnDaoshu)
	ON_BN_CLICKED(IDC_JIECEHG, OnJiecehg)
	ON_BN_CLICKED(IDC_PI, OnPi)
	ON_BN_CLICKED(IDC_SQR, OnSqr)
	ON_BN_CLICKED(IDC_XIANSHI, OnXianshi)
	ON_BN_CLICKED(IDC_BUXIANSHI, OnBuxianshi)
	ON_BN_CLICKED(IDC_QINGCHU, OnQingchu)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

BOOL CMyDlg::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);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
 /************************************************************************/
	//各种对象与编辑框、单选按钮、按钮等资源关联起来。
	//
	m_RadioHex.SubclassDlgItem(IDC_HEX,this);
	m_RadioDecimalist.SubclassDlgItem(IDC_DECIMALIST,this);
	m_RadioOctal.SubclassDlgItem(IDC_OCTAL,this);
	m_RadioBinary.SubclassDlgItem(IDC_BINARY,this);
	//
	m_RadioDegree.SubclassDlgItem(IDC_DEGREE,this);
	m_RadioRadian.SubclassDlgItem(IDC_RADIAN,this);
	//
	//
	m_Num0.SubclassDlgItem(IDC_Num_0,this);
	m_Num1.SubclassDlgItem(IDC_Num_1,this);
	m_Num2.SubclassDlgItem(IDC_Num_2,this);
	m_Num3.SubclassDlgItem(IDC_Num_3,this);
	m_Num4.SubclassDlgItem(IDC_Num_4,this);
	m_Num5.SubclassDlgItem(IDC_Num_5,this);
	m_Num6.SubclassDlgItem(IDC_NUM_6,this);
	m_Num7.SubclassDlgItem(IDC_Num_7,this);
	m_Num8.SubclassDlgItem(IDC_Num_8,this);
	m_Num9.SubclassDlgItem(IDC_Num_9,this);
	m_NumA.SubclassDlgItem(IDC_Num_10,this);
	m_NumB.SubclassDlgItem(IDC_Num_11,this);
	m_NumC.SubclassDlgItem(IDC_Num_12,this);
	m_NumD.SubclassDlgItem(IDC_Num_13,this);
	m_NumE.SubclassDlgItem(IDC_Num_14,this);
	m_NumF.SubclassDlgItem(IDC_Num_15,this);
	//
	m_OprAtan.SubclassDlgItem(IDC_ATAN,this);
	m_OprAcos.SubclassDlgItem(IDC_ACOS,this);
	m_OprAsin.SubclassDlgItem(IDC_ASIN,this);
	m_OprTan.SubclassDlgItem(IDC_TAN,this);
	m_OprCos.SubclassDlgItem(IDC_COS,this);
	m_OprSin.SubclassDlgItem(IDC_SIN,this);
	m_OprCot.SubclassDlgItem(IDC_COT,this);
	m_OprAcot.SubclassDlgItem(IDC_ACOT,this);

	//
	m_OprMo.SubclassDlgItem(IDC_MO,this);
	m_OprAc.SubclassDlgItem(IDC_AC,this);
	m_OprBack.SubclassDlgItem(IDC_Back,this);
	//
	m_OprDaoshu.SubclassDlgItem(IDC_DAOSHU,this);
	m_OprSqr.SubclassDlgItem(IDC_SQR,this);
	m_OprJiecehg.SubclassDlgItem(IDC_JIECEHG,this);
    m_OprExp.SubclassDlgItem(IDC_EXP,this);
	m_OprAdd.SubclassDlgItem(IDC_ADD,this);
	m_OprDec.SubclassDlgItem(IDC_DEC,this);
	m_OprMut.SubclassDlgItem(IDC_MUT,this);
	m_OprDiv.SubclassDlgItem(IDC_DIV,this);

	m_OprPi.SubclassDlgItem(IDC_PI,this);
	m_OprLog.SubclassDlgItem(IDC_LOG,this);
	m_OprLn.SubclassDlgItem(IDC_LN,this);
	m_OprMutmut.SubclassDlgItem(IDC_MUTMUT,this);
	m_OprDot.SubclassDlgItem(IDC_DOT,this);
	m_OprFuhao.SubclassDlgItem(IDC_FUHAO,this);
	m_OprEqual.SubclassDlgItem(IDC_Equal,this);
/**************************************************************************/
	//初始化单选按钮状态
	m_RadioDecimalist.SetCheck(1);		//十进制单选按钮初始化为选定
	m_RadioRadian.SetCheck(1);
	j=2;k=10;
	m_RadioHex.SetCheck(0);
	m_RadioOctal.SetCheck(0);
	m_RadioBinary.SetCheck(0);
	m_NumA.EnableWindow(FALSE);
	m_NumB.EnableWindow(FALSE);
	m_NumC.EnableWindow(FALSE);
	m_NumD.EnableWindow(FALSE);
	m_NumE.EnableWindow(FALSE);
	m_NumF.EnableWindow(FALSE);
	//
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	m_RadioRadian.EnableWindow(1);
	// TODO: Add extra initialization here
	UpdateData(FALSE);
	Restarted=true;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, 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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMyDlg::OnNum0() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="0";
	else
		m_strResult+="0";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum2() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="2";
	else
		m_strResult+="2";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnFuhao() //输入正负号
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_strResult.Left(m_strResult.GetLength())=="")
	 {Error(11);OperatorPressed=true;return;}
	 else 
	if(m_strResult.GetAt(0)=='-')
		m_strResult=m_strResult.Mid(1);
	else
		m_strResult="-"+m_strResult;
	 h=1;
	UpdateData(FALSE);
}



void CMyDlg::OnNum1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="1";
	else
		m_strResult+="1";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum3() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="3";
	else
		m_strResult+="3";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);	
}

void CMyDlg::OnNum4() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="4";
	else
		m_strResult+="4";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum5() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="5";
	else
		m_strResult+="5";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum6() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="6";
	else
		m_strResult+="6";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum7() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="7";
	else
		m_strResult+="7";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum8() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="8";
	else
		m_strResult+="8";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum9() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="9";
	else
		m_strResult+="9";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum10() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="A";
	else
		m_strResult+="A";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum11() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="B";
	else
		m_strResult+="B";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum12() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="C";
	else
		m_strResult+="C";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

void CMyDlg::OnNum13() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(OperatorPressed==true||Restarted==true)
		m_strResult="D";
	else
		m_strResult+="D";
	OperatorPressed=false;
	Restarted=false;
	h=1;
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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