📄 dlgcal.cpp
字号:
// DlgCal.cpp : implementation file
//
#include "stdafx.h"
#include "Ex_BDSYL.h"
#include "DlgCal.h"
#include<iostream.h>
#include<fstream.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "Calculat.cpp"
/////////////////////////////////////////////////////////////////////////////
// DlgCal dialog
DlgCal::DlgCal(CWnd* pParent /*=NULL*/)
: CDialog(DlgCal::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgCal)
m_result = _T("");
m_outfilename = _T("");
m_dataout = _T("");
m_datain = _T("");
//}}AFX_DATA_INIT
}
void DlgCal::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgCal)
DDX_Text(pDX, IDC_EDIT_RESULT, m_result);
DDX_Text(pDX, IDC_EDIT_OUTFILENAME, m_outfilename);
DDX_Text(pDX, IDC_EDIT_DATAOUT, m_dataout);
DDX_Text(pDX, IDC_EDIT_DATAIN, m_datain);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgCal, CDialog)
//{{AFX_MSG_MAP(DlgCal)
ON_BN_CLICKED(IDC_BUTTON_OUTFILE, OnButtonOutfile)
ON_BN_CLICKED(IDC_BUTTON_CALCULATE, OnButtonCalculate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgCal message handlers
void DlgCal::OnButtonOutfile()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(true);
if(dlg.DoModal()==IDOK)
{
m_outfilename=dlg.GetFileName();
UpdateData(false);
}
}
void DlgCal::OnButtonCalculate()
{
UpdateData(true);
if(m_datain=="")
{
MessageBox("表达式不能为空!!!");
return;
}
Calculator<Rational> m_Cal(50);
if(m_outfilename=="")
m_outfilename="Calculator.out";
Rational m_showResult=m_Cal.Run(m_datain,m_outfilename);
if(m_showResult.Getden()==1)
m_result.Format("%d",m_showResult.Getnum());
else
m_result.Format("%d/%d",m_showResult.Getnum(),m_showResult.Getden());
Dispdatafromfile(m_outfilename);
UpdateData(false);
// TODO: Add your control notification handler code here
}
void DlgCal::Dispdatafromfile(CString fname)
{
ifstream fin;
char ch;
fin.open(fname,ios::in|ios::nocreate);
if (!fin)
{
AfxMessageBox("文件不存在!");
return;
}
m_dataout="";
while(fin.get(ch))
{
if(ch=='\n')
m_dataout+="\r\n";
else
m_dataout+=ch;
}
fin.close();
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -