// Cacl2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Cacl2.h"
#include "Cacl2Dlg.h"
#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()
/////////////////////////////////////////////////////////////////////////////
// CCacl2Dlg dialog
CCacl2Dlg::CCacl2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CCacl2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCacl2Dlg)
m_x = 0.0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_first=0.0;m_second=0.0; //该行以下为初始化
m_firstz=0;m_firstx=0.0;
m_secondz=0;m_secondx=0.0;
m_firx=FALSE;m_secx=FALSE;
m_firxw=0;m_secxw=0;
m_firzorf=1;m_seczorf=1;
m_EnterSec=FALSE;
m_result=0.0;
m_ForS=1;
m_mfir=0.0;m_msec=0.0;m_mfun=0;
m_sfmf=FALSE;m_sfms=FALSE;m_sfmfun=FALSE;
}
void CCacl2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCacl2Dlg)
DDX_Control(pDX, IDC_RESULT, m_xedit);
DDX_Text(pDX, IDC_RESULT, m_x);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCacl2Dlg, CDialog)
//{{AFX_MSG_MAP(CCacl2Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_0, On0)
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_BACK, OnBack)
ON_BN_CLICKED(IDC_DIV, OnDiv)
ON_BN_CLICKED(IDC_GO, OnGo)
ON_BN_CLICKED(IDC_ON, OnOn)
ON_BN_CLICKED(IDC_SUB, OnSub)
ON_BN_CLICKED(IDC_TIM, OnTim)
ON_BN_CLICKED(IDC_XSD, OnXsd)
ON_BN_CLICKED(IDC_ZFH, OnZfh)
ON_BN_CLICKED(IDC_ABTATH, OnAbtath)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCacl2Dlg message handlers
void CCacl2Dlg::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 CCacl2Dlg::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 CCacl2Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCacl2Dlg::On0() //输入0
{
// TODO: Add your control notification handler code here
AddNum(0);
}
void CCacl2Dlg::On1() //输入1
{
// TODO: Add your control notification handler code here
AddNum(1);
}
void CCacl2Dlg::On2() //输入2
{
// TODO: Add your control notification handler code here
AddNum(2);
}
void CCacl2Dlg::On3() //输入3
{
// TODO: Add your control notification handler code here
AddNum(3);
}
void CCacl2Dlg::On4() //输入4
{
// TODO: Add your control notification handler code here
AddNum(4);
}
void CCacl2Dlg::On5() //输入5
{
// TODO: Add your control notification handler code here
AddNum(5);
}
void CCacl2Dlg::On6() //输入6
{
// TODO: Add your control notification handler code here
AddNum(6);
}
void CCacl2Dlg::On7() //输入7
{
// TODO: Add your control notification handler code here
AddNum(7);
}
void CCacl2Dlg::On8() //输入8
{
// TODO: Add your control notification handler code here
AddNum(8);
}
void CCacl2Dlg::On9() //输入9
{
// TODO: Add your control notification handler code here
AddNum(9);
}
void CCacl2Dlg::OnAdd() //输入+
{
// TODO: Add your control notification handler code here
AddFun(1);
}
void CCacl2Dlg::OnBack() //按back键
{
// TODO: Add your control notification handler code here
if(m_ForS==1) //如果此时在输入第一个数
{
if(m_firx==FALSE) //如果此时在输入整数部分
{ if(m_firstz<10) //如果整数部分小于10
{
m_firstz=0; //改为0
m_firzorf=1; //置符号为正
}
else
{
int y1=(int)m_firstz;//y1为一与整数部分相等的数
y1/=10; //去掉个位数
m_firstz=y1;
}
}
else //如果在输入小数部分
{
if(m_firxw==1) //此时小数部分只有一位
{
m_firstx=0.0;m_firxw=0;m_firx=FALSE;//小数部分清为0
}
else
{
int y2=(int)(m_firstx*pow(10,m_firxw)); //取一整数与小数点所有的数表示的整数相等,如123等于0.123的小数部分表示的数
y2/=10;m_firxw--; //去掉最后一位
m_firstx=y2*pow(10,(-1)*m_firxw);
}
}
m_first=m_firzorf*(m_firstz+m_firstx); //计算出第一个数
m_x=m_first;UpdateData(FALSE); //显示它
}
else if(m_ForS==2) //如果在输入第二个数,处理方法同第一个数
{
if(m_secx==FALSE)
{
if(m_secondz<10)
{
m_secondz=0;
m_seczorf=1;
}
else
{
int y3=(int)m_secondz;
y3/=10;
m_secondz=y3;
}
}
else
{
if(m_secxw==1)
{
m_secondx=0.0;m_secxw=0;m_secx=FALSE;
}
else
{
int y4=(int)(m_secondx*pow(10,m_secxw));
y4/=10;m_secxw--;
m_secondx=y4*pow(10,(-1)*m_secxw);
}
}
m_second=m_seczorf*(m_secondz+m_secondx);
m_x=m_second;UpdateData(FALSE);
}
}
void CCacl2Dlg::OnDiv() //输入/
{
// TODO: Add your control notification handler code here
AddFun(4);
}
void CCacl2Dlg::OnGo() //按=号运算
{
// TODO: Add your control notification handler code here
if(m_sfmf==TRUE&&m_sfms==TRUE&&m_sfmfun==TRUE) //如果记着第一,二个数和运算符,即上次算完后未输入数,而再次按=
{
if(m_mfun==1)m_result=m_mfir+m_msec; //m_fun为1,则用上次的数和符号加,下同
else if(m_mfun==2)m_result=m_mfir-m_msec; //m_fun为2,则减,下同
else if(m_mfun==3)m_result=m_mfir*m_msec; //为3,则乘,下同
else if(m_mfun==4)m_result=m_mfir/m_msec; //为4,则除,下同
m_sfmf=TRUE;m_sfms=TRUE;m_sfmfun=TRUE; //记住参加运算的数和运算符
m_mfir=m_result;m_msec=m_msec;m_mfun=m_mfun;
}
else if(m_sfmf==TRUE&&m_sfms==FALSE&&m_sfmfun==FALSE)//只记的第一数,如算完2+3=5后按*4=
{
if(m_fun==1)m_result=m_mfir+m_second;
else if(m_fun==2)m_result=m_mfir-m_second;
else if(m_fun==3)m_result=m_mfir*m_second;
else if(m_fun==4)m_result=m_mfir/m_second;
m_sfmf=TRUE;m_sfms=TRUE;m_sfmfun=TRUE;
m_mfir=m_result;m_msec=m_second;m_mfun=m_fun;
}
else if(m_sfmf=TRUE&&m_sfms==TRUE&&m_sfmfun==FALSE) //记住了第一个数,未输入第二个数,输入了运算符.如算完2+3=5后�