// MFCApplication1Dlg.cpp: 实现文件
//
#include "pch.h"
#include "framework.h"
#include "MFCApplication1.h"
#include "MFCApplication1Dlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMFCApplication1Dlg 对话框
CMFCApplication1Dlg::CMFCApplication1Dlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_MFCAPPLICATION1_DIALOG, pParent)
, m_data(_T("0"))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMFCApplication1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT2, m_data);
}
BEGIN_MESSAGE_MAP(CMFCApplication1Dlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BNUM1, &CMFCApplication1Dlg::OnBnClickedBnum1)
ON_BN_CLICKED(IDC_BNUM2, &CMFCApplication1Dlg::OnBnClickedBnum2)
ON_BN_CLICKED(IDC_BNUM3, &CMFCApplication1Dlg::OnBnClickedBnum3)
ON_BN_CLICKED(IDC_BNUM4, &CMFCApplication1Dlg::OnBnClickedBnum4)
ON_BN_CLICKED(IDC_BNUM5, &CMFCApplication1Dlg::OnBnClickedBnum5)
ON_BN_CLICKED(IDC_BNUM6, &CMFCApplication1Dlg::OnBnClickedBnum6)
ON_BN_CLICKED(IDC_BNUM7, &CMFCApplication1Dlg::OnBnClickedBnum7)
ON_BN_CLICKED(IDC_BNUM28, &CMFCApplication1Dlg::OnBnClickedBnum28)
ON_BN_CLICKED(IDC_BNUM9, &CMFCApplication1Dlg::OnBnClickedBnum9)
ON_BN_CLICKED(IDC_BNUM0, &CMFCApplication1Dlg::OnBnClickedBnum0)
ON_BN_CLICKED(IDC_FEATURE2, &CMFCApplication1Dlg::OnBnClickedFeature2)
ON_BN_CLICKED(IDC_ADD, &CMFCApplication1Dlg::OnBnClickedAdd)
ON_BN_CLICKED(IDC_SUB, &CMFCApplication1Dlg::OnBnClickedSub)
ON_BN_CLICKED(IDC_MUL, &CMFCApplication1Dlg::OnBnClickedMul)
ON_BN_CLICKED(IDC_DIV, &CMFCApplication1Dlg::OnBnClickedDiv)
ON_BN_CLICKED(IDC_DEL, &CMFCApplication1Dlg::OnBnClickedDel)
ON_BN_CLICKED(IDC_C, &CMFCApplication1Dlg::OnBnClickedC)
ON_BN_CLICKED(IDC_CE, &CMFCApplication1Dlg::OnBnClickedCe)
ON_BN_CLICKED(IDC_EQUAL, &CMFCApplication1Dlg::OnBnClickedEqual)
ON_BN_CLICKED(IDC_FEATURE6, &CMFCApplication1Dlg::OnBnClickedFeature6)
ON_BN_CLICKED(IDC_FEATURE3, &CMFCApplication1Dlg::OnBnClickedFeature3)
ON_BN_CLICKED(IDC_FEATURE4, &CMFCApplication1Dlg::OnBnClickedFeature4)
ON_BN_CLICKED(IDC_FEATURE5, &CMFCApplication1Dlg::OnBnClickedFeature5)
ON_BN_CLICKED(IDC_FEATURE1, &CMFCApplication1Dlg::OnBnClickedFeature1)
END_MESSAGE_MAP()
// CMFCApplication1Dlg 消息处理程序
BOOL CMFCApplication1Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
// 设置对话框的父窗口为NULL,使其独立存在
//-----------------------------------------------------
SetParent(NULL);
CRgn m_rgn;
RECT rc;
GetWindowRect(&rc);
// 有边框对话框
m_rgn.CreateRoundRectRgn(rc.left, rc.top, rc.right, rc.bottom, 40, 40);
// 矩形圆角
SetWindowRgn(m_rgn, TRUE);
//---------------------------------------------------
//--------------------------------------------------------------------
int nDstWidth = 1280;
int nDstHeight = 900;
//得到显示器大小
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
//再用MoveWindow
CRect rcTemp;
rcTemp.TopLeft() = CPoint(cx / 2 - nDstWidth / 2, cy / 2 - nDstHeight / 2);
rcTemp.BottomRight() = CPoint(cx / 2 + nDstWidth / 2, cy / 2 + nDstHeight / 2);
MoveWindow(&rcTemp);
//--------------------------------------------------------------------
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CMFCApplication1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
//————————————————————————————————
CPaintDC dc(this); // 用于绘制的设备上下文
CRect rect;
GetClientRect(rect);
dc.FillSolidRect(rect, RGB(235, 246, 249)); //设置为蓝色背景
CDialogEx::OnPaint();
//-----------------------------------------------------------------
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CMFCApplication1Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
CString a[1000] = {0};
int i = 1;
int pd = 0;//用于判断每个数只含一个小数点
int f = 0;//用于加减乘除不能连用
void CMFCApplication1Dlg::OnBnClickedBnum1()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if (m_data == "0")
{
i--;
a[i] = "1";
m_data = a[i];
}
else
{
a[i] = "1";
m_data += a[i];
}
f = 0;
i++;
UpdateData(false);
}
void CMFCApplication1Dlg::OnBnClickedBnum2()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if (m_data == "0")
{
i--;
a[i] = "2";
m_data = a[i];
}
else
{
a[i] = "2";
m_data += a[i];
}
f = 0;
i++;
UpdateData(false);
}
void CMFCApplication1Dlg::OnBnClickedBnum3()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if (m_data == "0")
{
i--;
a[i] = "3";
m_data = a[i];
}
else
{
a[i] = "3";
m_data += a[i];
}
f = 0;
i++;
UpdateData(false);
}
void CMFCApplication1Dlg::OnBnClickedBnum4()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if (m_data == "0")
{
i--;
a[i] = "4";
m_data = a[i];
}
else
{
a[i] = "4";
m_data += a[i];
}
f = 0;
i++;
UpdateData(false);
}
void CMFCApplication1Dlg::OnBnClickedBnum5()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if (m_data == "0")
{
i--;
a[i] = "5";
m_data = a[i];
}
else
{
a[i] = "5";
m_data += a[i];
}
f = 0;
i++;
UpdateData(false);
}
void CMFCApplication1Dlg::OnBnClickedBnum6()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if (m_data == "0")
{
i--;
a[i] = "6";
m_data = a[i];
}
else
{
a[i] = "6";
m_data += a[i];
}
f = 0;
i++;
UpdateData(false);
}
void CMFCApplication1Dlg::OnBnClickedBnum7()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if (m_data == "0")
{
i--;
a[i] = "7";
m_data = a[i];
}
else
{
a[i] = "7";
m_data += a[i];
}
f = 0;
i++;
UpdateData(false);
}
void CMFCApplication1Dlg::OnBnClickedBnum28()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if (m_data == "0")
{
i--;
a[i] = "8";
m_data = a[i];
}
else
{
a[i] = "8";
m_data += a[i];
}
f = 0;
i++;
UpdateData(false);
}
void CMFCApplication1Dlg::OnBnClickedBnum9()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if (m_data == "0")
{
i--;
a[i] = "9";
m_data = a[i];
}
else
{
a[i] = "9";
m_data += a[i];
}
f = 0;
i++;
UpdateData(false);
}
void CMFCApplication1Dlg::OnBnClickedBnum0()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if (m_data == "0")
{
i--;
a[i] = "0";
m_data = a[i];
}
else
{
a[i] = "0";
m_data += a[i];
}
f = 0;
i++;
UpdateData(false);
}
void CMFCApplication1Dlg::OnBnClickedFe