📄 calculatorguidlg.cpp
字号:
void CCalculatorGUIDlg::OnButtonArctan()
{
// TODO: Add your control notification handler code here
clickBtn("arctan");
}
void CCalculatorGUIDlg::OnButtonSqrt()
{
// TODO: Add your control notification handler code here
clickBtn("sqrt");
}
void CCalculatorGUIDlg::OnButtonMod()
{
// TODO: Add your control notification handler code here
clickBtn("mod");
}
void CCalculatorGUIDlg::OnButtonExp()
{
// TODO: Add your control notification handler code here
clickBtn("exp");
}
void CCalculatorGUIDlg::OnButtonLn()
{
// TODO: Add your control notification handler code here
clickBtn("ln");
}
void CCalculatorGUIDlg::OnButtonLog()
{
// TODO: Add your control notification handler code here
clickBtn("log");
}
void CCalculatorGUIDlg::OnButtonGiaithua()
{
// TODO: Add your control notification handler code here
clickBtn("!");
}
void CCalculatorGUIDlg::OnButtonPow()
{
// TODO: Add your control notification handler code here
clickBtn("^");
}
void CCalculatorGUIDlg::OnButtonTohop()
{
// TODO: Add your control notification handler code here
clickBtn("C");
}
void CCalculatorGUIDlg::OnButtonChinhhop()
{
// TODO: Add your control notification handler code here
clickBtn("P");
}
void CCalculatorGUIDlg::OnButtonAbs()
{
// TODO: Add your control notification handler code here
clickBtn("abs");
}
void CCalculatorGUIDlg::OnButtonNgoac1()
{
// TODO: Add your control notification handler code here
clickBtn("(");
}
void CCalculatorGUIDlg::OnButtonNgoac2()
{
// TODO: Add your control notification handler code here
clickBtn(")");
}
void CCalculatorGUIDlg::OnButtonCeil()
{
// TODO: Add your control notification handler code here
clickBtn("ceil");
}
void CCalculatorGUIDlg::OnButtonFloor()
{
// TODO: Add your control notification handler code here
clickBtn("floor");
}
void CCalculatorGUIDlg::OnButtonPi()
{
// TODO: Add your control notification handler code here
clickBtn("PI");
}
void CCalculatorGUIDlg::OnButtonM()
{
// TODO: Add your control notification handler code here
kqnho = add(kqnho,ketqua);
UpdateData(TRUE);
m_nho = "M";
UpdateData(FALSE);
}
void CCalculatorGUIDlg::OnButtonMsub()
{
// TODO: Add your control notification handler code here
kqnho = sub(kqnho,ketqua);
UpdateData(TRUE);
m_nho = "M";
UpdateData(FALSE);
}
void CCalculatorGUIDlg::OnButtonMc()
{
// TODO: Add your control notification handler code here
kqnho = 0;
UpdateData(TRUE);
m_nho = "";
Invalidate(TRUE);
UpdateData(FALSE);
}
void CCalculatorGUIDlg::OnButtonMr()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_In = "";
m_Out.Format("%f",kqnho);
m_Out = processResult(m_Out);
Invalidate(TRUE);
UpdateData(FALSE);
}
void CCalculatorGUIDlg::OnButtonC()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_In = "";
m_Out = "";
UpdateData(FALSE);
}
void CCalculatorGUIDlg::OnButtonDelete()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_In != "")
{
int length = m_In.GetLength();
m_In = m_In.Left(length-1);
}
UpdateData(FALSE);
}
void CCalculatorGUIDlg::OnRadioDeg()
{
// TODO: Add your control notification handler code here
degree = TRUE;
}
void CCalculatorGUIDlg::OnRadioRadient()
{
// TODO: Add your control notification handler code here
degree = FALSE;
}
void CCalculatorGUIDlg::OnSystemofequations()
{
// TODO: Add your command handler code here
CDlgSOE * dlgSOE = new CDlgSOE();
BOOL check = dlgSOE->Create(IDD_DIALOG_SOE,this);
if (!check)
{
MessageBox("This page isn't available.");
}
else
{
dlgSOE->ShowWindow(SW_SHOW);
}
}
void CCalculatorGUIDlg::OnHelpAbout()
{
// TODO: Add your command handler code here
CAboutDlg dlg;
dlg.DoModal();
}
void CCalculatorGUIDlg::OnEquation()
{
// TODO: Add your command handler code here
CDlgEquation * dlgEqua = new CDlgEquation();
BOOL check = dlgEqua->Create(IDD_DIALOG_EQUATION,this);
if (!check)
{
MessageBox("This page isn't available");
}
else
{
dlgEqua->ShowWindow(SW_SHOW);
}
}
void CCalculatorGUIDlg::OnDrawGraph()
{
// TODO: Add your command handler code here
CDlgDrawGraph * dlgGraph = new CDlgDrawGraph();
BOOL check = dlgGraph->Create(IDD_DIALOG_GRAPH,this);
if (!check)
{
MessageBox("This page isn't available");
}
else
{
dlgGraph->ShowWindow(SW_SHOW);
}
}
void CCalculatorGUIDlg::OnButtonAns()
{
// TODO: Add your control notification handler code here
clickBtn("ANS");
}
void CCalculatorGUIDlg::OnRadioBin()
{
// TODO: Add your control notification handler code here
m_bin = TRUE;
UpdateData(TRUE);
CDiagram objD;
m_In = objD.CheckDecFormula(m_In);
if (m_Out != "")
{
m_Out = objD.CheckDecFormula(m_Out);
Invalidate(TRUE);
}
controlButtons(FALSE);
UpdateData(FALSE);
}
void CCalculatorGUIDlg::OnRadioDec()
{
// TODO: Add your control notification handler code here
m_bin = FALSE;
UpdateData(TRUE);
CDiagram objD;
m_In = objD.CheckBinFormula(m_In);
if (m_Out != "")
{
m_Out = objD.CheckBinFormula(m_Out);
Invalidate(TRUE);
}
controlButtons(TRUE);
UpdateData(FALSE);
}
void CCalculatorGUIDlg::OnChangeEditIn()
{
equal = FALSE;
}
void CCalculatorGUIDlg::OnDblclkListHistory()
{
// TODO: Add your control notification handler code here
int pos = m_history.GetCurSel();
CString ex = "";
m_history.GetText(pos,ex);
UpdateData(TRUE);
m_In = ex;
m_Out = "";
Invalidate(TRUE);
UpdateData(FALSE);
equal = FALSE;
}
// Xu li viec do dai bieu thuc nhap vao lon hon be rong cua listbox trong history
int CCalculatorGUIDlg::AddString2List(LPCTSTR s)
{
int result = m_history.AddString(s);
if(result < 0)
return result;
updateWidth(s);
return result;
}
void CCalculatorGUIDlg::clickBtn(CString s)
{
UpdateData(TRUE);
if (equal)
{
m_In = "";
equal = FALSE;
}
m_In += s;
UpdateData(FALSE);
}
// Xu li viec goi cac lop dll de tinh toan
bool CCalculatorGUIDlg::calculate(CString ex)
{
ex.MakeUpper();
ex.Replace(_T("ANS"),m_ans);
CBalanceAl objBalance;
CDiagram objD;
CString temp;
CStringArray exs,res;
int erpos;
ex = objD.Replace(ex);
if (m_bin)
{
ex = objD.CheckBinFormula(ex);
}
erpos = objD.Run(ex);
if(erpos < 0)
{
if(!objBalance.BalanceAl(ex,ketqua,degree))
{
m_Out="Math error !^^!";
Invalidate(TRUE);
return FALSE;
}
else
{
temp.Format("%f",ketqua);
m_Out = processResult(temp);
m_ans = m_Out;
if (m_bin)
{
m_Out = objD.Dec2Bin(m_Out);
}
Invalidate(TRUE);
return TRUE;
}
}
else
{
m_cInput.SetSel(erpos,erpos+1,FALSE);
temp.Format("Syntax error at position %d !@@!",erpos);
m_Out = temp;
Invalidate(TRUE);
}
return FALSE;
}
// Xu li viec dua 1 anh bitmap lam background cho Dialog (co tham khao nguon ngoai)
BOOL CCalculatorGUIDlg::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 CCalculatorGUIDlg::SetBitmap(UINT nIDResource)
{
if(m_bitmap.LoadBitmap(nIDResource))
return 0;
else
return 1;//error
}
// Xu li phan transparent CStatic voi background cua Dialog (co tham khao nguon ngoai)
HBRUSH CCalculatorGUIDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr;
if(nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT);
hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
}
return hbr;
}
// Xu li su kien khi nguoi dung nhan phim enter
BOOL CCalculatorGUIDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_RETURN)
{
pMsg->wParam = NULL;
OnButtonEqual();
}
else
{
if (equal)
{
UpdateData(TRUE);
m_In = "";
UpdateData(FALSE);
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
// Xu li chuoi ket qua xuat ra khi dap so lon hon 16 chu so
CString CCalculatorGUIDlg::processResult(CString s)
{
int size = 16;
int j=0,range=0,i=0,count=0;
int f=s.Find('.');
int l=s.GetLength();
CString temp="",m="";
if(l>size){
if(f>=0) range = f+1;
else range = l;
//xu ly phan nguyen
if(range>size){
j = range-size-1;
m=s.Left(size);
temp.Format("*10^%d",j);
m+=temp;
}
else m=s.Left(size);
}
else m=s;
i=m.GetLength()-1;
while((m.GetAt(i)=='0')&&(i>f)) i--;
if(i==f) m=m.Left(f);
else m=m.Left(i+1);
return m;
}
// Xu li viec lam mo nut khi nguoi dung chon radio button BIN
void CCalculatorGUIDlg::controlButtons(BOOL state)
{
m_btnTohop.EnableWindow(state);
m_btnTan.EnableWindow(state);
m_btnSqrt.EnableWindow(state);
m_btnSin.EnableWindow(state);
m_btnPow.EnableWindow(state);
m_btnPi.EnableWindow(state);
m_btnMod.EnableWindow(state);
m_btnLog.EnableWindow(state);
m_btnLn.EnableWindow(state);
m_btnGiaithua.EnableWindow(state);
m_btnFloor.EnableWindow(state);
m_btnExp.EnableWindow(state);
m_btnDot.EnableWindow(state);
m_btnCos.EnableWindow(state);
m_btnChinhhop.EnableWindow(state);
m_btnCeil.EnableWindow(state);
m_btnArctan.EnableWindow(state);
m_btnArcsin.EnableWindow(state);
m_btnArccos.EnableWindow(state);
m_btnAbs.EnableWindow(state);
m_btn9.EnableWindow(state);
m_btn8.EnableWindow(state);
m_btn7.EnableWindow(state);
m_btn6.EnableWindow(state);
m_btn5.EnableWindow(state);
m_btn4.EnableWindow(state);
m_btn3.EnableWindow(state);
m_btn2.EnableWindow(state);
m_btnAns.EnableWindow(state);
m_btnNgoac1.EnableWindow(state);
m_btnNgoac2.EnableWindow(state);
m_btnMAdd.EnableWindow(state);
m_btnMR.EnableWindow(state);
m_btnMSub.EnableWindow(state);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -