⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calculatordlg.cpp

📁 一个用VC写的计算器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// CalculatorDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Calculator.h"
#include "CalculatorDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CCalculatorDlg dialog

CCalculatorDlg::CCalculatorDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCalculatorDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCalculatorDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    m_Menu = NULL;
	m_IsExtend = FALSE;	

	m_IsCheckPoint = false;
	m_StrBegin = "";
	m_begin = 0.0;
	m_end = 0.0;
	m_bit = 0;
}

void CCalculatorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCalculatorDlg)
	 DDX_Control(pDX,IDC_DSPSTATIC,m_DspStatic);//静态框
     DDX_Control(pDX,IDC_DSPEDIT,m_DspEdit);//编辑框
	 
	 //将按钮控件与CAdvButton对象相关联
	 
 DDX_Control(pDX,BTN_0,m_AdvButton0);
 DDX_Control(pDX,BTN_1,m_AdvButton1);
 DDX_Control(pDX,BTN_2,m_AdvButton2);
 DDX_Control(pDX,BTN_3,m_AdvButton3);
 DDX_Control(pDX,BTN_4,m_AdvButton4);
 DDX_Control(pDX,BTN_5,m_AdvButton5);
 DDX_Control(pDX,BTN_6,m_AdvButton6);
 DDX_Control(pDX,BTN_7,m_AdvButton7);
 DDX_Control(pDX,BTN_8,m_AdvButton8);
 DDX_Control(pDX,BTN_9,m_AdvButton9);
 DDX_Control(pDX,BTN_10,m_AdvButtonPoint);
 DDX_Control(pDX,BTN_11,m_AdvButtonEqu);
 DDX_Control(pDX,BTN_12,m_AdvButtonAdd);
 DDX_Control(pDX,BTN_13,m_AdvButtonSub);
 DDX_Control(pDX,BTN_14,m_AdvButtonMul);
 DDX_Control(pDX,BTN_15,m_AdvButtonDiv);
 DDX_Control(pDX,BTN_16,m_AdvButtonClear);
 DDX_Control(pDX,BTN_17,m_AdvButtonSqrt);
 DDX_Control(pDX,BTN_18,m_AdvButtonReverse);
 DDX_Control(pDX,BTN_19,m_AdvButtonSin);
 DDX_Control(pDX,BTN_20,m_AdvButtonCos);
 DDX_Control(pDX,BTN_21,m_AdvButtonTan);
 DDX_Control(pDX,BTN_22,m_AdvButtonSqu);
 DDX_Control(pDX,BTN_23,m_AdvButtonCub);
 DDX_Control(pDX,BTN_24,m_AdvButtonPow);
 DDX_Control(pDX,BTN_25,m_AdvButtonExp);
 DDX_Control(pDX,BTN_26,m_AdvButtonLn);
 DDX_Control(pDX,BTN_27,m_AdvButtonLog);
 DDX_Control(pDX,BTN_28,m_AdvButtonZof);
 DDX_Control(pDX,BTN_29,m_AdvButtonN);
 DDX_Control(pDX,BTN_30,m_AdvButton10X);
 DDX_Control(pDX,BTN_31,m_AdvButtonAbout);
 DDX_Control(pDX,BTN_32,m_AdvButtonOff);
 
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCalculatorDlg, CDialog)
	//{{AFX_MSG_MAP(CCalculatorDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(BTN_0, On0)
	ON_BN_CLICKED(BTN_1, On1)
	ON_BN_CLICKED(BTN_10, On10)
	ON_BN_CLICKED(BTN_11, On11)
	ON_BN_CLICKED(BTN_12, On12)
	ON_BN_CLICKED(BTN_13, On13)
	ON_BN_CLICKED(BTN_14, On14)
	ON_BN_CLICKED(BTN_15, On15)
	ON_BN_CLICKED(BTN_16, On16)
	ON_BN_CLICKED(BTN_17, On17)
	ON_BN_CLICKED(BTN_18, On18)
	ON_BN_CLICKED(BTN_19, On19)
	ON_BN_CLICKED(BTN_2, On2)
	ON_BN_CLICKED(BTN_20, On20)
	ON_BN_CLICKED(BTN_21, On21)
	ON_BN_CLICKED(BTN_22, On22)
	ON_BN_CLICKED(BTN_23, On23)
	ON_BN_CLICKED(BTN_24, On24)
	ON_BN_CLICKED(BTN_25, On25)
	ON_BN_CLICKED(BTN_26, On26)
	ON_BN_CLICKED(BTN_27, On27)
	ON_BN_CLICKED(BTN_3, On3)
	ON_BN_CLICKED(BTN_4, On4)
	ON_BN_CLICKED(BTN_5, On5)
	ON_BN_CLICKED(BTN_6, On6)
	ON_BN_CLICKED(BTN_7, On7)
	ON_BN_CLICKED(BTN_8, On8)
	ON_BN_CLICKED(BTN_9, On9)
	ON_COMMAND(ID_EXTEND, OnExtend)
	ON_BN_CLICKED(BTN_28, OnZOF)
	ON_BN_CLICKED(BTN_29, OnN)
	ON_BN_CLICKED(BTN_30, On10X)
	ON_BN_CLICKED(BTN_31, OnABOUT)
	ON_BN_CLICKED(IDC_HEX, OnHex)
	ON_BN_CLICKED(IDC_OCT, OnOct)
	ON_BN_CLICKED(IDC_RAD, OnRad)
	ON_BN_CLICKED(IDC_DEC, OnDec)
	ON_BN_CLICKED(IDC_BIN, OnBin)
	ON_BN_CLICKED(IDC_DEGREE, OnDegree)
	ON_BN_CLICKED(IDC_TIDU, OnTidu)
	ON_BN_CLICKED(BTN_32, OnOK)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCalculatorDlg message handlers

BOOL CCalculatorDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.
	m_Menu=new CMenu;//
	m_Menu->LoadMenu(IDR_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
	SetMenu(m_Menu);//将菜单资源添加到对话框
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCalculatorDlg::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 CCalculatorDlg::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 CCalculatorDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCalculatorDlg::On0() 
{
	// TODO: Add your control notification handler code here
	m_StrBegin=m_StrBegin+"0";

	if(!m_IsCheckPoint)//如果小数点按下了
		 m_DspEdit.OnDisplay(m_StrBegin+".");
	else//如果小数点没有按下
		m_DspEdit.OnDisplay(m_StrBegin);
}

void CCalculatorDlg::On1() 
{
	// TODO: Add your control notification handler code here
		m_StrBegin=m_StrBegin+"1";

	if(!m_IsCheckPoint)//如果小数点按下了
		 m_DspEdit.OnDisplay(m_StrBegin+".");
	else//如果小数点没有按下
		m_DspEdit.OnDisplay(m_StrBegin);
}

void CCalculatorDlg::On10() 
{
	// TODO: Add your control notification handler code here
	if(!m_IsCheckPoint&&m_StrBegin!="")//如果小数点没有按下,且字符串不为空
	{
		m_StrBegin=m_StrBegin+".";
		m_DspEdit.OnDisplay(m_StrBegin);//显示文本

		m_IsCheckPoint=true;//改变标识
	}
}

void CCalculatorDlg::On11() 
{
	// TODO: Add your control notification handler code here
	Result();
	m_bit=7;
}

void CCalculatorDlg::On12() 
{
	// TODO: Add your control notification handler code here
	Result();
	m_bit=1;
}

void CCalculatorDlg::On13() 
{
	// TODO: Add your control notification handler code here
	Result();
	m_bit=2;
}

void CCalculatorDlg::On14() 
{
	// TODO: Add your control notification handler code here
	Result();
	m_bit=3;
}

void CCalculatorDlg::On15() 
{
	// TODO: Add your control notification handler code here
	Result();
	m_bit=4;
}

void CCalculatorDlg::On16() 
{
	// TODO: Add your control notification handler code here
	m_IsCheckPoint=false;

	m_StrBegin="";
	m_begin=0.0;
	m_end=0.0;
	m_bit=0;
	m_DspEdit.OnDisplay("0.");
}

void CCalculatorDlg::On17() 
{
	// TODO: Add your control notification handler code here
	Result();
	m_bit=5;
}

void CCalculatorDlg::On18() 
{
	// TODO: Add your control notification handler code here
	Result();
	m_bit=6;
}

void CCalculatorDlg::On19() 
{
	// TODO: Add your control notification handler code here
	Result();
	m_bit=8;
}

void CCalculatorDlg::On2() 
{
	// TODO: Add your control notification handler code here
		m_StrBegin=m_StrBegin+"2";

	if(!m_IsCheckPoint)//如果小数点按下了
		 m_DspEdit.OnDisplay(m_StrBegin+".");
	else//如果小数点没有按下
		m_DspEdit.OnDisplay(m_StrBegin);
}

void CCalculatorDlg::On20() 
{
	// TODO: Add your control notification handler code here
	Result();
	m_bit=9;
}

void CCalculatorDlg::On21() 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -