?? 計(jì)算器dlg.cpp
字號(hào):
// 計(jì)算器Dlg.cpp : implementation file
//
#include "math.h"
#include "stdafx.h"
#include "計(jì)算器.h"
#include "計(jì)算器Dlg.h"
//#include "stdlib.h"
//#include "iostream.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()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
m_edit = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Text(pDX, IDC_EDIT3, m_edit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON10, OnButton0)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
ON_BN_CLICKED(IDC_BUTTON13, On_jia)
ON_BN_CLICKED(IDC_BUTTON14, On_jian)
ON_BN_CLICKED(IDC_BUTTON15, On_cheng)
ON_BN_CLICKED(IDC_BUTTON16, On_chu)
ON_BN_CLICKED(IDC_BUTTON20, On_dengyu)
ON_BN_CLICKED(IDC_BUTTON17, On_sqrt)
ON_BN_CLICKED(IDC_BUTTON18, On_C)
ON_BN_CLICKED(IDC_BUTTON19, On_Exit)
ON_BN_CLICKED(IDC_BUTTON11, On_ZF)
ON_BN_CLICKED(IDC_BUTTON22, On_1X)
ON_BN_CLICKED(IDC_BUTTON23, On_BaiFen)
ON_BN_CLICKED(IDC_BUTTON21, On_BackSpace)
ON_BN_CLICKED(IDC_BUTTON12, On_Dian)
ON_BN_CLICKED(IDC_BUTTON25, On_sin)
ON_BN_CLICKED(IDC_BUTTON26, On_cos)
ON_BN_CLICKED(IDC_BUTTON27, On_tan)
ON_BN_CLICKED(IDC_BUTTON28, On_arcsin)
ON_BN_CLICKED(IDC_BUTTON29, On_arccos)
ON_BN_CLICKED(IDC_BUTTON30, On_arctan)
ON_BN_CLICKED(IDC_BUTTON31, On_exp)
ON_BN_CLICKED(IDC_BUTTON35, On_log)
ON_BN_CLICKED(IDC_BUTTON36, On_lg)
ON_BN_CLICKED(IDC_BUTTON32, On_save)
ON_BN_CLICKED(IDC_BUTTON33, On_average)
ON_BN_CLICKED(IDC_BUTTON37, On_sum)
ON_BN_CLICKED(IDC_BUTTON38, On_sumx2)
ON_BN_CLICKED(IDC_BUTTON39, On_s)
ON_BN_CLICKED(IDC_BUTTON40, On_jiecheng)
ON_BN_CLICKED(IDC_BUTTON41, On_del)
ON_BN_CLICKED(IDC_BUTTON34, On_n)
ON_BN_CLICKED(IDC_BUTTON24, OnButton24)
ON_BN_CLICKED(IDC_BUTTON42, On_start)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnButton0()
{
// TODO: Add your control notification handler code here
m_edit=m_edit+"0";
UpdateData(FALSE);
}
void CMyDlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_edit=m_edit+"1";
UpdateData(FALSE);
}
void CMyDlg::OnButton2()
{
// TODO: Add your control notification handler code here
m_edit=m_edit+"2";
UpdateData(FALSE);
}
void CMyDlg::OnButton3()
{
// TODO: Add your control notification handler code here
m_edit=m_edit+"3";
UpdateData(FALSE);
}
void CMyDlg::OnButton4()
{
// TODO: Add your control notification handler code here
m_edit=m_edit+"4";
UpdateData(FALSE);
}
void CMyDlg::OnButton5()
{
// TODO: Add your control notification handler code here
m_edit=m_edit+"5";
UpdateData(FALSE);
}
void CMyDlg::OnButton6()
{
// TODO: Add your control notification handler code here
m_edit=m_edit+"6";
UpdateData(FALSE);
}
void CMyDlg::OnButton7()
{
// TODO: Add your control notification handler code here
m_edit=m_edit+"7";
UpdateData(FALSE);
}
void CMyDlg::OnButton8()
{
// TODO: Add your control notification handler code here
m_edit=m_edit+"8";
UpdateData(FALSE);
}
void CMyDlg::OnButton9()
{
// TODO: Add your control notification handler code here
m_edit=m_edit+"9";
UpdateData(FALSE);
}
void CMyDlg::On_jia()
{
// TODO: Add your control notification handler code here
iQian=atof(m_edit);
iType=1;
UpdateData(FALSE); //顯示所輸入的數(shù)據(jù)
m_edit="";
}
void CMyDlg::On_jian()
{
// TODO: Add your control notification handler code here
iQian=atof(m_edit);
iType=2;
UpdateData(FALSE);
m_edit="";
}
void CMyDlg::On_cheng()
{
// TODO: Add your control notification handler code here
iQian=atof(m_edit);
iType=3;
UpdateData(FALSE);
m_edit="";
}
void CMyDlg::On_chu()
{
// TODO: Add your control notification handler code here
iQian=atof(m_edit);
iType=4;
UpdateData(FALSE);
m_edit="";
}
void CMyDlg::On_dengyu()
{
// TODO: Add your control notification handler code here
double iRet=0;
switch(iType)
{
case 1:
iRet = iQian + atoi(m_edit);
break;
case 2:
iRet = iQian - atoi(m_edit);
break;
case 3:
iRet = iQian * atoi(m_edit);
break;
case 4:
if (atoi(m_edit)!=0)
{
iRet = iQian / atoi(m_edit);
break;
}
else
{
MessageBox("can't use zero!") ;
}
return;
}
//將結(jié)果轉(zhuǎn)成字符串,并顯示
char cRet[50],temp[50];
int str;
memset(cRet,0,50);
memset(temp,0,50);
sprintf(cRet,"%f",iRet);
str = strlen(cRet);
str=str-1;
while(str>0){
if(cRet[str]=='0'&&cRet[str]!='.')
{
str--;
}
else
break;
}
for(int i=0;i<=str;i++)
{
temp[i]=cRet[i];
}
m_edit = temp;
UpdateData(FALSE);
//所有iQian與iType清0
iQian=0;
iType=0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -