// cacuDlg.cpp : implementation file
//
#include "stdafx.h"
#include "cacu.h"
#include "cacuDlg.h"
#include "math.h"
#include "cstring"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CCacuDlg dialog
CCacuDlg::CCacuDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCacuDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCacuDlg)
m_s = _T("");
m_M = _T("");
p=0,q=0,w=1,c='r';
Ispoint=false;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCacuDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCacuDlg)
DDX_Text(pDX, IDC_EDIT1, m_s);
DDX_Text(pDX, IDC_EDIT2, m_M);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCacuDlg, CDialog)
//{{AFX_MSG_MAP(CCacuDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDC_BackSpace, OnBackSpace) ON_BN_CLICKED(IDC_Clear2, OnClear)
ON_BN_CLICKED(IDC_1, On1)
ON_BN_CLICKED(IDC_2, On2)
ON_BN_CLICKED(IDC_3, On3)
ON_BN_CLICKED(IDC_4, On4)
ON_BN_CLICKED(IDC_5, On5)
ON_BN_CLICKED(IDC_6, On6)
ON_BN_CLICKED(IDC_7, On7)
ON_BN_CLICKED(IDC_8, On8)
ON_BN_CLICKED(IDC_9, On9)
ON_BN_CLICKED(IDC_add, Onadd)
ON_BN_CLICKED(IDC_Sub, OnSub)
ON_BN_CLICKED(IDC_Mul, OnMul)
ON_BN_CLICKED(IDC_div, Ondiv)
ON_BN_CLICKED(IDC_Sqrt, OnSqrt)
ON_BN_CLICKED(IDC_point, Onpoint)
ON_BN_CLICKED(IDC_0, On0)
ON_BN_CLICKED(IDC_Sin, OnSin)
ON_BN_CLICKED(IDC_Cos, OnCos)
ON_BN_CLICKED(IDC_power_2, Onpower2)
ON_BN_CLICKED(IDC_power_3, Onpower3)
ON_BN_CLICKED(IDC_Equar, OnEquar)
ON_BN_CLICKED(IDC_1_x, On1x)
ON_BN_CLICKED(IDC_1_100, On1100)
ON_BN_CLICKED(IDC_MS, OnMs)
ON_BN_CLICKED(IDC_MC, OnMc)
ON_BN_CLICKED(IDC_MR, OnMr)
ON_BN_CLICKED(IDC_Madd, OnMadd)
ON_BN_CLICKED(IDC_Msub, OnMsub)
ON_EN_CHANGE(IDC_EDIT2, OnM)
ON_BN_CLICKED(IDC_sub_add, Onsubadd)
ON_BN_CLICKED(IDC_CE, OnCe)
ON_BN_CLICKED(IDC_PI, OnPi)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCacuDlg message handlers
BOOL CCacuDlg::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);
}
}
// 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
m_s="0.";
UpdateData(false);
m_s="";
CFont *m_Font;
m_Font = new CFont;
m_Font->CreateFont(50,20,0,0,100,
FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS,"Arial");
CEdit *m_Edit1=(CEdit *)GetDlgItem(IDC_EDIT1);
m_Edit1->SetFont(m_Font,FALSE);
GetDlgItem(IDC_EDIT1)->SetFont(m_Font);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCacuDlg::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 CCacuDlg::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 CCacuDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCacuDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CCacuDlg::OnBackSpace()
{
// TODO: Add your control notification handler code here
int uu=0;
m_s.Delete(m_s.GetLength()-1,1);
if(w==1)
temp1=atof(m_s);
else
temp2=atof(m_s);
if(m_s.Find('.')<0)
Ispoint=false;
else
Ispoint=true;
if(m_s.GetLength()==0)
{
m_s="0.";
uu=1;
c='r';
}
if(!uu&&!Ispoint)
m_s+=".";
UpdateData(false);
if(!uu&&!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
if(uu==1)
m_s="";
}
void CCacuDlg::OnClear()
{
// TODO: Add your control notification handler code here UpdateData(true);
m_s="0.";
temp2=temp1=0;
w=1;
c='r';
UpdateData(false);
m_s="";
}
void CCacuDlg::On1()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
p=0;
}
m_s=m_s+"1";
if(!Ispoint)
m_s+=".";
UpdateData(false);
if(!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
if(w==1)
temp1=atof(m_s),temp2=0;
else if(w==2)
temp2=atof(m_s);
//c='1';
}
void CCacuDlg::On2()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
p=0;
}
//UpdateData(true);
m_s=m_s+"2";
if(!Ispoint)
UpdateData(false);
//c='1';
if(!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
if(w==1)
temp1=atof(m_s),temp2=0;
else if(w==2)
temp2=atof(m_s);
}
void CCacuDlg::On3()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
p=0;
}
//UpdateData(true);
m_s=m_s+"3";
if(!Ispoint)
m_s+=".";
UpdateData(false);
if(!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
if(w==1)
temp1=atof(m_s),temp2=0;
else if(w==2)
temp2=atof(m_s);
//c='1';
}
void CCacuDlg::On4()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
p=0;
}
//UpdateData(true);
if(!Ispoint)
m_s+=".";
UpdateData(false);
if(!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
//c='1';
if(w==1)
temp1=atof(m_s),temp2=0;
else if(w==2)
temp2=atof(m_s);
}
void CCacuDlg::On5()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
p=0;
}
//UpdateData(true);
m_s=m_s+"5";
if(!Ispoint)
m_s+=".";
UpdateData(false);
if(!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
//c='1';
if(w==1)
temp1=atof(m_s);
else if(w==2)
temp2=atof(m_s);
}
void CCacuDlg::On6()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
p=0;
}
//UpdateData(true);
m_s=m_s+"6";
if(!Ispoint)
m_s+=".";
UpdateData(false);
if(!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
//c='1';
if(w==1)
temp1=atof(m_s),temp2=0;
else if(w==2)
temp2=atof(m_s);
}
void CCacuDlg::On7()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
p=0;
}
m_s=m_s+"7";
if(!Ispoint)
m_s+=".";
UpdateData(false);
if(!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
//c='1';
if(w==1)
temp1=atof(m_s),temp2=0;
else if(w==2)
temp2=atof(m_s);
}
void CCacuDlg::On8()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
}
//UpdateData(true);
m_s=m_s+"8";
if(!Ispoint)
m_s+=".";
UpdateData(false);
if(!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
//c='1';
if(w==1)
temp1=atof(m_s),temp2=0;
else if(w==2)
temp2=atof(m_s);
}
void CCacuDlg::On9()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
p=0;
}
m_s=m_s+"9";
if(!Ispoint)
m_s+=".";
UpdateData(false);
if(!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
if(w==1)
temp1=atof(m_s),temp2=0;
else if(w==2)
temp2=atof(m_s);
}
void CCacuDlg::On0()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
}
//UpdateData(true);
m_s=m_s+"0";
if(!Ispoint)
m_s+=".";
UpdateData(false);
if(!Ispoint)
m_s.Delete(m_s.GetLength()-1,1);
//c='1';
if(w==1)
temp1=atof(m_s),temp2=0;
else if(w==2)
temp2=atof(m_s);
}
void CCacuDlg::Onadd()
{
// TODO: Add your control notification handler code here UpdateData(true);
Ispoint=false;
p=1;
if(w==2)
{
if(c=='+')
temp1=temp2+temp1;
else if(c=='-')
temp1=temp1-temp2;
else if(c=='*')
temp1*=temp2;
else if(c=='/')
temp1/=temp2;
else if(c=='s')
temp1=sin(atof(m_s));
else if(c=='c')
temp1=cos(atof(m_s));
m_s.Format("%.10lf",temp1);
//m_s+=".";
int n;
n=m_s.Find('.');
if (n>=0)
{
m_s.TrimRight('0');
if (m_s.GetLength()==n+1)
{
m_s=m_s.Left(n+1);
if (m_s.IsEmpty())
m_s='0';
}
}
UpdateData(false);
}
w=2;
c='+';
//Ispoint=false;
//UpdateData(false);
}
void CCacuDlg::OnSub()
{
// TODO: Add your control notification handler code here UpdateData(true);
Ispoint=false;
p=1;
if(w==2)
{
if(c=='+')
temp1=temp2+temp1;
else if(c=='-')
temp1=temp1-temp2;
else if(c=='*')
temp1*=temp2;
else if(c=='/')
temp1/=temp2;
else if(c=='s')
temp1=sin(atof(m_s));
else if(c=='c')
temp1=cos(atof(m_s));
m_s.Format("%.10lf",temp1);
int n;
n=m_s.Find('.');
if (n>=0)
{
m_s.TrimRight('0');
if (m_s.GetLength()==n+1)
{
m_s=m_s.Left(n+1);
if (m_s.IsEmpty())
m_s='0';
}
}
UpdateData(false);
}
w=2;
c='-';
//Ispoint=false;
//UpdateData(false);
}
void CCacuDlg::OnMul()
{
// TODO: Add your control notification handler code here UpdateData(true);
Ispoint=false;
p=1;
if(w==1)
temp2=1;
else
{
if(c=='+')
temp1=temp2+temp1;
else if(c=='-')
temp1=temp1-temp2;
else if(c=='*')
temp1*=temp2;
else if(c=='/')
temp1/=temp2;
else if(c=='s')
temp1=sin(atof(m_s));
else if(c=='c')
temp1=cos(atof(m_s));
m_s.Format("%.10lf",temp1);
int n;
n=m_s.Find('.');
if (n>=0)
{
m_s.TrimRight('0');
if (m_s.GetLength()==n+1)
{
m_s=m_s.Left(n+1);
if (m_s.IsEmpty())
m_s='0';
}
}
UpdateData(false);
}
c='*';
w=2;
//Ispoint=false;
}
void CCacuDlg::Ondiv()
{
// TODO: Add your control notification handler code here UpdateData(true);
Ispoint=false;
p=1;
if(w==1)
temp2=1.0;
else
{
if(c=='+')
temp1=temp2+temp1;
else if(c=='-')
temp1=temp1-temp2;
else if(c=='*')
temp1*=temp2;
else if(c=='/')
temp1/=temp2;
else if(c=='s')
temp1=sin(atof(m_s));
else if(c=='c')
temp1=cos(atof(m_s));
m_s.Format("%.10lf",temp1);
int n;
n=m_s.Find('.');
if (n>=0)
{
m_s.TrimRight('0');
if (m_s.GetLength()==n+1)
{
m_s=m_s.Left(n+1);
if (m_s.IsEmpty())
m_s='0';
}
}
UpdateData(false);
}
c='/';
w=2;
}
void CCacuDlg::OnSqrt()
{
// TODO: Add your control notification handler code here Ispoint=false;
temp1=sqrt(atof(m_s));
m_s.Format("%.10lf",temp1);
int n;
n=m_s.Find('.');
if (n>=0)
{
m_s.TrimRight('0');
if (m_s.GetLength()==n+1)
{
m_s=m_s.Left(n+1);
if (m_s.IsEmpty())
m_s='0';
}
}
p=q=1;
w=1;
c='r';
UpdateData(false);
}
void CCacuDlg::Onpoint()
{
// TODO: Add your control notification handler code here if(p==1)
{
m_s="";
UpdateData(false);
p=0;
}
//UpdateData(true);
m_s=m_s+".";
Ispoint=true;
UpdateData(false);
}
void CCacuDlg::OnSin()
{
// TODO: Add your control notification handler code here c='s';
p=q=1;
w=2;
}
void CCacuDlg::OnCos()
{
// TODO: Add your control notification handler code here c='c';
p=q=1;
w=2;
}
void CCacuDlg::Onpower2()
{
// TODO: Add your control notification handler code here Ispoint=false;
temp1=atof(m_s);
temp1=temp1*temp1;
m_s.Format("%.10lf",temp1);
int n;
n=m_s.Find('.');
if (n>=0)
{
m_s.TrimRight('0');
if (m_s.GetLength()==n+1)
{
m_s=m_s.Left(n+1);
if (m_s.IsEmpty())
m_s='0';
}
}
p=q=1;
w=1;
c='r';
UpdateData(false);
}
void CCacuDlg::Onpower3()
{
// TODO: Add your control notification handler code here Ispoint=false;
temp1=atof(m_s);
temp1=temp1*temp1*temp1;
m_s.Format("%.10lf",temp1);
int n;
n=m_s.Find('.');
if (n>=0)
{
m_s.TrimRight('0');
if (m_s.GetLength()==n+1)
{
m_s=m_s.Left(n+1);
if (m_s.IsEmpty())
m_s='0';
}
}
p=q=1;
w=1;
c='r';
UpdateData(false);
}
void CCacuDlg::OnEquar()
{
// TODO: Add your control notification handler code here int yy=0;
if(c=='+'||c=='r')
temp=temp1+temp2;
else if(c=='-')
temp=temp1-temp2;
else if(c=='*')
temp=temp1*temp2;
else if(c=='/')
{
if(temp2==0)
yy=1;
else
temp=temp1/temp2;
}
else if(c=='s')
temp=sin(atof(m_s));
else if(c=='c')
temp=cos(atof(m_s));
m_s.Format("%.10lf",temp),temp1=temp;
//m_s+=".";
int n;
n=m_s.Find('.');
//UpdateData(false);
if (n>=0)
{
m_s.TrimRight('0');
if (m_s.GetLength()==n+1)
{
m_s=m_s.Left(n+1);
if (m_s.IsEmpty())
m_s='0';
}
}
p=1;w=1;
Ispoint=false;
//temp1=temp;
c='r';
if(yy==1)
m_s="除数不能为0";
UpdateData(false);
if(yy==1)
m_s=="";
}
void CCacuDlg::On1x()
{
// TODO: Add your control notification handler code here int yy=0;
if(m_s=="0")
yy=1;
else
temp1=1.0/atof(m_s);
m_s.Format("%.10lf",temp1);
int n;
n=m_s.Find('.');
if (n>=0)
{
m_s.TrimRight('0');
if (m_s.GetLength()==n+1)
{
m_s=m_s.Left(n+1);
if (m_s.IsEmpty())
m_s='0';
}
}
p=1;
w=1;
c='r';
Ispoint=false;
if(yy==1)
m_s="分母不能为0",yy=1;
UpdateData(false);
if(yy==1)
m_s="";
}
void CCacuDlg::On1100()
{
// TODO: Add your control notification handler code here //if(p==1)
Ispoint=false;
int yy=0;
if(c=='+'||c=='r')
temp=temp1+temp2;
else if(c=='-')
temp=temp1-temp2;
else if(c=='*')
temp=temp1*temp2;
else if(c=='/')
{
if(temp2==0)
yy=1;
else
temp=temp1/temp2;
}
else if(c=='s')
temp=sin(atof(m_s));
else if(c=='c')
temp=cos(atof(m_s));
m_s.Format("%.10lf",temp),temp1=temp;
m_s.Format("%.10lf",temp/100.0);
int n;