📄 calculatorguidlg.cpp
字号:
// CalculatorGUIDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CalculatorGUI.h"
#include "CalculatorGUIDlg.h"
#include "DlgEquation.h"
#include "DlgDrawGraph.h"
#include "Lib/BalanceAl.h"
#include "Lib/Diagram.h"
#include "Lib/CalculatorDLL.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:
int SetBitmap(UINT nIDResource);
CBitmap m_bitmap;
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)
virtual BOOL OnInitDialog();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
//}}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)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
SetBitmap(IDB_BITMAP2);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CAboutDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnEraseBkgnd(pDC);
if(!m_bitmap.m_hObject)
return true;
CRect rect;
GetClientRect(&rect);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dc.SelectObject(&m_bitmap);
int bmw, bmh ;
BITMAP bmap;
m_bitmap.GetBitmap(&bmap);
bmw = bmap.bmWidth;
bmh = bmap.bmHeight;
int xo=0, yo=0;
if(bmw < rect.Width())
xo = (rect.Width() - bmw)/2;
else
xo=0;
if(bmh < rect.Height())
yo = (rect.Height()-bmh)/2;
else
yo=0;
pDC->BitBlt (xo, yo, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY);
dc.SelectObject(pOldBitmap);
return true;
}
int CAboutDlg::SetBitmap(UINT nIDResource)
{
if(m_bitmap.LoadBitmap(nIDResource))
return 0;
else
return 1;//error
}
HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr;
if(nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT);
hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
}
return hbr;
}
/////////////////////////////////////////////////////////////////////////////
// CCalculatorGUIDlg dialog
CCalculatorGUIDlg::CCalculatorGUIDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCalculatorGUIDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCalculatorGUIDlg)
m_In = _T("");
m_Out = _T("");
m_nho = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCalculatorGUIDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCalculatorGUIDlg)
DDX_Control(pDX, IDC_BUTTON_MSUB, m_btnMSub);
DDX_Control(pDX, IDC_BUTTON_MR, m_btnMR);
DDX_Control(pDX, IDC_BUTTON_M, m_btnMAdd);
DDX_Control(pDX, IDC_BUTTON_NGOAC2, m_btnNgoac2);
DDX_Control(pDX, IDC_BUTTON_NGOAC1, m_btnNgoac1);
DDX_Control(pDX, IDC_BUTTON_ANS, m_btnAns);
DDX_Control(pDX, IDC_BUTTON_TOHOP, m_btnTohop);
DDX_Control(pDX, IDC_BUTTON_TAN, m_btnTan);
DDX_Control(pDX, IDC_BUTTON_SQRT, m_btnSqrt);
DDX_Control(pDX, IDC_BUTTON_SIN, m_btnSin);
DDX_Control(pDX, IDC_BUTTON_POW, m_btnPow);
DDX_Control(pDX, IDC_BUTTON_PI, m_btnPi);
DDX_Control(pDX, IDC_BUTTON_MOD, m_btnMod);
DDX_Control(pDX, IDC_BUTTON_LOG, m_btnLog);
DDX_Control(pDX, IDC_BUTTON_LN, m_btnLn);
DDX_Control(pDX, IDC_BUTTON_GIAITHUA, m_btnGiaithua);
DDX_Control(pDX, IDC_BUTTON_FLOOR, m_btnFloor);
DDX_Control(pDX, IDC_BUTTON_EXP, m_btnExp);
DDX_Control(pDX, IDC_BUTTON_DOT, m_btnDot);
DDX_Control(pDX, IDC_BUTTON_COS, m_btnCos);
DDX_Control(pDX, IDC_BUTTON_CHINHHOP, m_btnChinhhop);
DDX_Control(pDX, IDC_BUTTON_CEIL, m_btnCeil);
DDX_Control(pDX, IDC_BUTTON_ARCTAN, m_btnArctan);
DDX_Control(pDX, IDC_BUTTON_ARCSIN, m_btnArcsin);
DDX_Control(pDX, IDC_BUTTON_ARCCOS, m_btnArccos);
DDX_Control(pDX, IDC_BUTTON_ABS, m_btnAbs);
DDX_Control(pDX, IDC_BUTTON_9, m_btn9);
DDX_Control(pDX, IDC_BUTTON_8, m_btn8);
DDX_Control(pDX, IDC_BUTTON_7, m_btn7);
DDX_Control(pDX, IDC_BUTTON_6, m_btn6);
DDX_Control(pDX, IDC_BUTTON_5, m_btn5);
DDX_Control(pDX, IDC_BUTTON_4, m_btn4);
DDX_Control(pDX, IDC_BUTTON_3, m_btn3);
DDX_Control(pDX, IDC_BUTTON_2, m_btn2);
DDX_Control(pDX, IDC_EDIT_IN, m_cInput);
DDX_Control(pDX, IDC_LIST_HISTORY, m_history);
DDX_Text(pDX, IDC_EDIT_IN, m_In);
DDX_Text(pDX, IDC_EDIT_OUT, m_Out);
DDX_Text(pDX, IDC_STATIC_M, m_nho);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCalculatorGUIDlg, CDialog)
//{{AFX_MSG_MAP(CCalculatorGUIDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
ON_BN_CLICKED(IDC_BUTTON_EQUAL, OnButtonEqual)
ON_BN_CLICKED(IDC_BUTTON_1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON_2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON_3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON_4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON_5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON_6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON_7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON_8, OnButton8)
ON_BN_CLICKED(IDC_BUTTON_9, OnButton9)
ON_BN_CLICKED(IDC_BUTTON_0, OnButton0)
ON_BN_CLICKED(IDC_BUTTON_DOT, OnButtonDot)
ON_BN_CLICKED(IDC_BUTTON_NEG, OnButtonNeg)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_SUB, OnButtonSub)
ON_BN_CLICKED(IDC_BUTTON_MUL, OnButtonMul)
ON_BN_CLICKED(IDC_BUTTON_DIV, OnButtonDiv)
ON_BN_CLICKED(IDC_BUTTON_SIN, OnButtonSin)
ON_BN_CLICKED(IDC_BUTTON_COS, OnButtonCos)
ON_BN_CLICKED(IDC_BUTTON_TAN, OnButtonTan)
ON_BN_CLICKED(IDC_BUTTON_ARCSIN, OnButtonArcsin)
ON_BN_CLICKED(IDC_BUTTON_ARCCOS, OnButtonArccos)
ON_BN_CLICKED(IDC_BUTTON_ARCTAN, OnButtonArctan)
ON_BN_CLICKED(IDC_BUTTON_SQRT, OnButtonSqrt)
ON_BN_CLICKED(IDC_BUTTON_MOD, OnButtonMod)
ON_BN_CLICKED(IDC_BUTTON_EXP, OnButtonExp)
ON_BN_CLICKED(IDC_BUTTON_LN, OnButtonLn)
ON_BN_CLICKED(IDC_BUTTON_LOG, OnButtonLog)
ON_BN_CLICKED(IDC_BUTTON_GIAITHUA, OnButtonGiaithua)
ON_BN_CLICKED(IDC_BUTTON_POW, OnButtonPow)
ON_BN_CLICKED(IDC_BUTTON_TOHOP, OnButtonTohop)
ON_BN_CLICKED(IDC_BUTTON_CHINHHOP, OnButtonChinhhop)
ON_BN_CLICKED(IDC_BUTTON_ABS, OnButtonAbs)
ON_BN_CLICKED(IDC_BUTTON_NGOAC1, OnButtonNgoac1)
ON_BN_CLICKED(IDC_BUTTON_NGOAC2, OnButtonNgoac2)
ON_BN_CLICKED(IDC_BUTTON_CEIL, OnButtonCeil)
ON_BN_CLICKED(IDC_BUTTON_FLOOR, OnButtonFloor)
ON_BN_CLICKED(IDC_BUTTON_PI, OnButtonPi)
ON_BN_CLICKED(IDC_BUTTON_M, OnButtonM)
ON_BN_CLICKED(IDC_BUTTON_MC, OnButtonMc)
ON_BN_CLICKED(IDC_BUTTON_MR, OnButtonMr)
ON_LBN_DBLCLK(IDC_LIST_HISTORY, OnDblclkListHistory)
ON_BN_CLICKED(IDC_BUTTON_C, OnButtonC)
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
ON_BN_CLICKED(IDC_RADIO_DEG, OnRadioDeg)
ON_BN_CLICKED(IDC_RADIO_RADIENT, OnRadioRadient)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
ON_COMMAND(ID_SPECIALFUNCTIONS_SYSTEMOFEQUATIONS, OnSystemofequations)
ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
ON_COMMAND(ID_SPECIALFUNCTIONS_EQUATION, OnEquation)
ON_BN_CLICKED(IDC_BUTTON_ANS, OnButtonAns)
ON_BN_CLICKED(IDC_RADIO_BIN, OnRadioBin)
ON_BN_CLICKED(IDC_RADIO_DEC, OnRadioDec)
ON_EN_CHANGE(IDC_EDIT_IN, OnChangeEditIn)
ON_COMMAND(ID_DRAW_GRAPH, OnDrawGraph)
ON_BN_CLICKED(IDC_BUTTON_MSUB, OnButtonMsub)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCalculatorGUIDlg message handlers
BOOL CCalculatorGUIDlg::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
width = 0;
equal = FALSE; //chua nhan dau =
degree = TRUE; //May tinh dang o che do tinh toan theo do
CheckRadioButton(IDC_RADIO_DEG,IDC_RADIO_DEG,IDC_RADIO_DEG);
m_bin = FALSE;
CheckRadioButton(IDC_RADIO_DEC,IDC_RADIO_DEC,IDC_RADIO_DEC);
ketqua = 0;
kqnho = 0;
m_ans = "0";
SetBitmap(IDB_BITMAP3);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCalculatorGUIDlg::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 CCalculatorGUIDlg::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 CCalculatorGUIDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCalculatorGUIDlg::updateWidth(LPCTSTR s)
{
CClientDC dc(this);
CFont * f = m_history.GetFont();
dc.SelectObject(f);
CSize sz = dc.GetTextExtent(s, _tcslen(s));
sz.cx += 3 * ::GetSystemMetrics(SM_CXBORDER);
if(sz.cx > width)
{
width = sz.cx;
m_history.SetHorizontalExtent(width);
}
}
void CCalculatorGUIDlg::OnButtonClear()
{
// TODO: Add your control notification handler code here
m_history.ResetContent();
}
void CCalculatorGUIDlg::OnButtonEqual()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_In != "")
{
equal = TRUE;
if (calculate(m_In))
{
m_history.AddString(m_In);
updateWidth(m_In);
}
}
UpdateData(FALSE);
}
void CCalculatorGUIDlg::OnButton1()
{
// TODO: Add your control notification handler code here
clickBtn("1");
}
void CCalculatorGUIDlg::OnButton2()
{
// TODO: Add your control notification handler code here
clickBtn("2");
}
void CCalculatorGUIDlg::OnButton3()
{
// TODO: Add your control notification handler code here
clickBtn("3");
}
void CCalculatorGUIDlg::OnButton4()
{
// TODO: Add your control notification handler code here
clickBtn("4");
}
void CCalculatorGUIDlg::OnButton5()
{
// TODO: Add your control notification handler code here
clickBtn("5");
}
void CCalculatorGUIDlg::OnButton6()
{
// TODO: Add your control notification handler code here
clickBtn("6");
}
void CCalculatorGUIDlg::OnButton7()
{
// TODO: Add your control notification handler code here
clickBtn("7");
}
void CCalculatorGUIDlg::OnButton8()
{
// TODO: Add your control notification handler code here
clickBtn("8");
}
void CCalculatorGUIDlg::OnButton9()
{
// TODO: Add your control notification handler code here
clickBtn("9");
}
void CCalculatorGUIDlg::OnButton0()
{
// TODO: Add your control notification handler code here
clickBtn("0");
}
void CCalculatorGUIDlg::OnButtonDot()
{
// TODO: Add your control notification handler code here
clickBtn(".");
}
void CCalculatorGUIDlg::OnButtonNeg()
{
// TODO: Add your control notification handler code here
clickBtn("-");
}
void CCalculatorGUIDlg::OnButtonAdd()
{
// TODO: Add your control notification handler code here
clickBtn("+");
}
void CCalculatorGUIDlg::OnButtonSub()
{
// TODO: Add your control notification handler code here
clickBtn("-");
}
void CCalculatorGUIDlg::OnButtonMul()
{
// TODO: Add your control notification handler code here
clickBtn("*");
}
void CCalculatorGUIDlg::OnButtonDiv()
{
// TODO: Add your control notification handler code here
clickBtn("/");
}
void CCalculatorGUIDlg::OnButtonSin()
{
// TODO: Add your control notification handler code here
clickBtn("sin");
}
void CCalculatorGUIDlg::OnButtonCos()
{
// TODO: Add your control notification handler code here
clickBtn("cos");
}
void CCalculatorGUIDlg::OnButtonTan()
{
// TODO: Add your control notification handler code here
clickBtn("tan");
}
void CCalculatorGUIDlg::OnButtonArcsin()
{
// TODO: Add your control notification handler code here
clickBtn("arcsin");
}
void CCalculatorGUIDlg::OnButtonArccos()
{
// TODO: Add your control notification handler code here
clickBtn("arccos");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -