📄 jisuandlg.cpp
字号:
// JISUANDlg.cpp : implementation file
//
#include "stdafx.h"
#include "JISUAN.h"
#include "JISUANDlg.h"
#include <math.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()
/////////////////////////////////////////////////////////////////////////////
// CJISUANDlg dialog
CJISUANDlg::CJISUANDlg(CWnd* pParent /*=NULL*/)
: CDialog(CJISUANDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CJISUANDlg)
m_text = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
flgPressDot=false;
flgPrevOptlsCacu=false;
// flgeqest=false;
ZF = '-';
}
void CJISUANDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJISUANDlg)
DDX_Text(pDX, IDC_EDIT1, m_text);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJISUANDlg, CDialog)
//{{AFX_MSG_MAP(CJISUANDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTT7, OnButt7)
ON_BN_CLICKED(IDC_BUTT8, OnButt8)
ON_BN_CLICKED(IDC_BUTT9, OnButt9)
ON_BN_CLICKED(IDC_BUTT4, OnButt4)
ON_BN_CLICKED(IDC_BUTT5, OnButt5)
ON_BN_CLICKED(IDC_BUTT6, OnButt6)
ON_BN_CLICKED(IDC_BUTT1, OnButt1)
ON_BN_CLICKED(IDC_BUTT2, OnButt2)
ON_BN_CLICKED(IDC_BUTT3, OnButt3)
ON_BN_CLICKED(IDC_BUTT0, OnButt0)
ON_BN_CLICKED(IDC_BUTTKong, OnBUTTKong)
ON_BN_CLICKED(IDC_BUTTJia, OnBUTTJia)
ON_BN_CLICKED(IDC_BUTTDengYu, OnBUTTDengYu)
ON_BN_CLICKED(IDC_BUTTJian, OnBUTTJian)
ON_BN_CLICKED(IDC_BUTTChen, OnBUTTChen)
ON_BN_CLICKED(IDC_BUTTChu, OnBUTTChu)
ON_BN_CLICKED(IDC_BUTTZF, OnButtzf)
ON_BN_CLICKED(IDC_BUTTSqrt, OnBUTTSqrt)
ON_BN_CLICKED(IDC_BUTTDian, OnBUTTDian)
ON_BN_CLICKED(IDC_BUTTKong2, OnBUTTKong2)
ON_BN_CLICKED(IDC_BUTTKong3, OnBUTTKong3)
ON_COMMAND(IDM_GuanYu,OnAboutClk)
ON_BN_CLICKED(IDC_BUTTDaoShu, OnBUTTDaoShu)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJISUANDlg message handlers
BOOL CJISUANDlg::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_edit.SubclassDlgItem(IDC_EDIT1,this);
m_text = "0.";
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
void CJISUANDlg::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 CJISUANDlg::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 CJISUANDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CJISUANDlg::OnAboutClk()
{
CAboutDlg dlg;
dlg.DoModal();
}
void CJISUANDlg::AddNum(int theNum) //此函数的作用是把输入的数据显示到文本框中
{
char oldText[100]= "";
char newText[100]= "";
strcpy(oldText,m_text);
if( flgPrevOptlsCacu==true)
{
strcpy(oldText,"0.");
flgPrevOptlsCacu=false;
}
if(false==flgPressDot)
{
double oldNum=atof(oldText);
double newNum=oldNum*10+theNum;
sprintf(newText,"%f",newNum);
TrimZero(newText);
m_text=newText;
UpdateData(false);
}else{
TrimZero(newText);
sprintf(newText,"%s%d",oldText,theNum);
m_text=newText;
UpdateData(false);
}
}
void CJISUANDlg::OnButt7()
{
// TODO: Add your control notification handler code here
AddNum(7);
}
void CJISUANDlg::OnButt8()
{
// TODO: Add your control notification handler code here
AddNum(8);
}
void CJISUANDlg::OnButt9()
{
// TODO: Add your control notification handler code here
AddNum(9);
}
void CJISUANDlg::OnButt4()
{
// TODO: Add your control notification handler code here
AddNum(4);
}
void CJISUANDlg::OnButt5()
{
// TODO: Add your control notification handler code here
AddNum(5);
}
void CJISUANDlg::OnButt6()
{
// TODO: Add your control notification handler code here
AddNum(6);
}
void CJISUANDlg::OnButt1()
{
// TODO: Add your control notification handler code here
AddNum(1);
}
void CJISUANDlg::OnButt2()
{
// TODO: Add your control notification handler code here
AddNum(2);
}
void CJISUANDlg::OnButt3()
{
// TODO: Add your control notification handler code here
AddNum(3);
}
void CJISUANDlg::OnButt0()
{
// TODO: Add your control notification handler code here
AddNum(0);
}
void CJISUANDlg::OnBUTTKong()
{
// TODO: Add your control notification handler code here
flgPressDot=false;
m_text = "0. ";
num1 = 0.0;
num2 = 0.0;
num = 0.0;
// flgeqest=false;
UpdateData(false);
}
void CJISUANDlg::OnBUTTJia()
{
// TODO: Add your control notification handler code here
flgPrevOptlsCacu=true;
flgPressDot=false;
c = '+';
num1 = atof(m_text);
m_text = "";
//flgeqest=true;
}
void CJISUANDlg::OnBUTTDengYu()
{
// TODO: Add your control notification handler code here
num2 = atof(m_text);
switch(c)
{
case '+':
num = num1 + num2;
/*if(flgeqest==true)
{
num1=num2;
}*/
break;
case '-':
num = num1 - num2;
break;
case '*':
num = num1 * num2;
break;
case '/':
num = num1 / num2;
break;
}
sprintf(m_num,"%lf",num);
funszNizhi(m_num);
m_text = m_num;
UpdateData(false);
}
void CJISUANDlg::OnBUTTJian()
{
// TODO: Add your control notification handler code here
flgPressDot=false;
c = '-';
num1 = atof(m_text);
m_text = "";
}
void CJISUANDlg::OnBUTTChen()
{
// TODO: Add your control notification handler code here
flgPressDot=false;
c = '*';
num1 = atof(m_text);
m_text = "";
}
void CJISUANDlg::OnBUTTChu()
{
// TODO: Add your control notification handler code here
flgPressDot=false;
c = '/';
num1 = atof(m_text);
m_text = "";
}
void CJISUANDlg::OnButtzf()
{
char ZF_text[100] = "";
double num;
num = atof(m_text);
// TODO: Add your control notification handler code here
switch(ZF)
{
flgPressDot=false;
case '-':
num = -1 * num;
sprintf(ZF_text,"%lf",num);
m_text = ZF_text;
ZF = '+';
break;
case '+':
num = -1 * num;
sprintf(ZF_text,"%lf",num);
m_text = ZF_text;
ZF = '-';
break;
}
UpdateData(false);
}
void CJISUANDlg::OnBUTTSqrt()
{
// TODO: Add your control notification handler code here
double theNum;
char textNum[100] = "";
theNum = atof(m_text);
sprintf(textNum,"%lf",sqrt(theNum));
funszNizhi(textNum);
m_text = textNum;
UpdateData(false);
}
void CJISUANDlg::funszNizhi(char *szNum)
{
int nLen=strlen(szNum)-1;
for(;nLen>=0;nLen--)
{
if(*(szNum+nLen)=='0' || *(szNum+nLen)=='.')
*(szNum+nLen)='\0';
else
break;
}
}
void CJISUANDlg::OnBUTTDian()
{
// TODO: Add your control notification handler code here
flgPressDot=true;
}
void CJISUANDlg::TrimZero(char *szText)
{
char *p;
char szNewText[100]="";
int nLen = strlen(szText);
p = szText;
p = p+nLen-1;
int nTrimCount=0;
for(int i=0;i<nLen;i++)
{if(*p!='0')
{
break;
}
nTrimCount++;
p--;
}
p=szText;
for(i=0;i<nLen-nTrimCount;i++)
{
sprintf(szNewText,"%s%c",szNewText,*p);
p++;
}
strcpy(szText,szNewText);
}
void CJISUANDlg::OnBUTTKong2()
{
// TODO: Add your control notification handler code here
flgPressDot=false;
m_text = "0. ";
num1 = 0.0;
num2 = 0.0;
num = 0.0;
UpdateData(false);
}
void CJISUANDlg::OnBUTTKong3()
{
// TODO: Add your control notification handler code here
double theNum;
char textNum[100] = "";
theNum = atol(m_text)/10;
sprintf(textNum,"%lf",theNum);
m_text = textNum;
if(theNum == 0)
{
m_text = "0.";
}
UpdateData(false);
}
void CJISUANDlg::OnBUTTDaoShu()
{
// TODO: Add your control notification handler code here
double theNum;
char textNum[100] = "";
theNum = 1/atof(m_text);
sprintf(textNum,"%lf",theNum);
m_text = textNum;
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -