📄 xycalcdlg.cpp
字号:
// XYCALCDlg.cpp : implementation file
//
//written by 熊英
#include "stdafx.h"
#include "XYCALC.h"
#include "XYCALCDlg.h"
#include "iostream.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <math.h>
#include <dos.h>
#include <direct.h>
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
const COLORREF LTGRAY = RGB(192, 192, 192);
const COLORREF RED = RGB(255, 0, 0);
const COLORREF BLUE = RGB(0, 0, 255);
const COLORREF DKGRAY = RGB(128, 128, 128);
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:
virtual BOOL OnInitDialog();
//{{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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXYCALCDlg dialog
CXYCALCDlg::CXYCALCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CXYCALCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CXYCALCDlg)
m_string = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hAccel = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD));
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CXYCALCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXYCALCDlg)
DDX_Control(pDX, IDC_EDIT1, m_editinia);
DDX_Text(pDX, IDC_EDIT1, m_string);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CXYCALCDlg, CDialog)
//{{AFX_MSG_MAP(CXYCALCDlg)
ON_WM_SYSCOMMAND()
ON_WM_DESTROY()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_BUTTON1, Ondevide)
ON_BN_CLICKED(ID_BUTTON2, Ontimes)
ON_BN_CLICKED(ID_BUTTON3, Onminus)
ON_BN_CLICKED(ID_BUTTON4, Onplus)
ON_BN_CLICKED(ID_BUTTON5, Onsqrt)
ON_BN_CLICKED(ID_BUTTON6, Onpercent)
ON_BN_CLICKED(ID_BUTTON7, Ondaoshu)
ON_BN_CLICKED(ID_BUTTON8, Onequal)
ON_BN_CLICKED(ID_10, Onzhengfu)
ON_BN_CLICKED(ID_11, Onpoint)
ON_BN_CLICKED(IDC_BUTTON2, Onbackspaces)
ON_BN_CLICKED(IDC_BUTTON1, Onclear)
ON_BN_CLICKED(IDC_MC, OnMc)
ON_BN_CLICKED(IDC_MS, OnMs)
ON_BN_CLICKED(IDC_MADD, OnMadd)
ON_BN_CLICKED(IDC_MR, OnMr)
ON_COMMAND(ID_MENUITEM32776, OnMenuitem32776)
ON_COMMAND(ID_MENUITEM32774, OnMenuitem32774)
ON_COMMAND(ID_MENUcopy, OnMENUcopy)
ON_COMMAND(ID_MENUpaste, OnMENUpaste)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_WM_CTLCOLOR()
ON_WM_CLOSE()
ON_COMMAND_RANGE(ID_0, ID_9, OnClickedNumber)
ON_BN_CLICKED(IDCANCEL1, OnCancel1)
ON_COMMAND(ID_HELP_CONTENTS, OnHelpContents)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXYCALCDlg message handlers
void CXYCALCDlg::addtip()
{
m_toolTip.Create( this );
CStringArray straInfo;
straInfo.RemoveAll();
straInfo.Add( "将数字放入计算器的显示区" );
int i=0;
for(i=0;i<10;i++)
m_toolTip.AddControlInfo( ID_0+i, straInfo );
straInfo.RemoveAll();
straInfo.Add( "清除存储区中的所有数值" );
m_toolTip.AddControlInfo( IDC_MC, straInfo );
straInfo.RemoveAll();
straInfo.Add( "重新调用存储区中的数值," );
straInfo.Add("调出的数值仍然保存在存储区中 ");
m_toolTip.AddControlInfo( IDC_MR, straInfo );
straInfo.RemoveAll();
straInfo.Add( "将显示的数值放入存储区中" );
m_toolTip.AddControlInfo( IDC_MS, straInfo );
straInfo.RemoveAll();
straInfo.Add( "将显示的数值与存储区中的数值相加" );
m_toolTip.AddControlInfo( IDC_MADD, straInfo );
straInfo.RemoveAll();
straInfo.Add( "改变显示数值的正负号" );
m_toolTip.AddControlInfo( ID_10, straInfo );
straInfo.RemoveAll();
straInfo.Add( "小数点" );
m_toolTip.AddControlInfo( ID_11, straInfo );
straInfo.RemoveAll();
straInfo.Add( "除法" );
m_toolTip.AddControlInfo( ID_BUTTON1, straInfo );
straInfo.RemoveAll();
straInfo.Add( "乘法" );
m_toolTip.AddControlInfo( ID_BUTTON2, straInfo );
straInfo.RemoveAll();
straInfo.Add( "减法" );
m_toolTip.AddControlInfo( ID_BUTTON3, straInfo );
straInfo.RemoveAll();
straInfo.Add( "加法" );
m_toolTip.AddControlInfo( ID_BUTTON4, straInfo );
straInfo.RemoveAll();
straInfo.Add( "计算显示数值的平方根" );
m_toolTip.AddControlInfo( ID_BUTTON5, straInfo );
straInfo.RemoveAll();
straInfo.Add( "按百分比的形式显示数值" );
m_toolTip.AddControlInfo( ID_BUTTON6, straInfo );
straInfo.RemoveAll();
straInfo.Add( "计算当前显示数值的倒数" );
m_toolTip.AddControlInfo( ID_BUTTON7, straInfo );
straInfo.RemoveAll();
straInfo.Add( "完成对上两个数的任意操作" );
m_toolTip.AddControlInfo( ID_BUTTON8, straInfo );
straInfo.RemoveAll();
straInfo.Add( "清除当前计算" );
m_toolTip.AddControlInfo( IDC_BUTTON1, straInfo );
straInfo.RemoveAll();
straInfo.Add( "删除当前显示数值的最后一位" );
m_toolTip.AddControlInfo( IDC_BUTTON2, straInfo );
straInfo.RemoveAll();
straInfo.Add( "清除当前显示的数值" );
m_toolTip.AddControlInfo( IDCANCEL1, straInfo );
straInfo.RemoveAll();
straInfo.Add( "一旦数据存储到存储区后,就显示M" );
m_toolTip.AddControlInfo( IDC_EDIT2, straInfo );
}
BOOL CXYCALCDlg::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
buttoncolor( );
GetDlgItem(IDC_EDIT1)->SetFocus( );
Onclear( );
addtip( );
/* m_toolTip.Create( this );
CStringArray straInfo;
straInfo.RemoveAll();
straInfo.Add( "Remove My Tooltip" );
m_toolTip.AddControlInfo( ID_7, straInfo, RGB(255,0,0), RGB(255,255,255) );
straInfo.RemoveAll();
straInfo.Add( "Cancel Button Control" );
m_toolTip.AddControlInfo( IDC_MC, straInfo, RGB(0,255,0) );
*/
return TRUE; // return TRUE unless you set the focus to a control
}
void CXYCALCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CXYCALCDlg::OnDestroy()
{
WinHelp(0L, HELP_QUIT);
CDialog::OnDestroy();
}
// 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 CXYCALCDlg::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 CXYCALCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CXYCALCDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CXYCALCDlg::OnCancel1()
{
// TODO: Add your control notification handler code here
Onclear();
}
void CXYCALCDlg::Ondevide()
{
// TODO: Add your control notification handler code here
perform( );
m_operator=OpDivide;
}
void CXYCALCDlg::Ontimes()
{
// TODO: Add your control notification handler code here
perform( );
m_operator = OpMultiply;
}
void CXYCALCDlg::Onminus()
{
// TODO: Add your control notification handler code here
perform( );
m_operator = OpSubtract;
}
void CXYCALCDlg::Onplus()
{
// TODO: Add your control notification handler code here
//GetDlgItem(IDC_EDIT1)->SetFocus( );
perform( );
m_operator = OpAdd;
}
void CXYCALCDlg::Onsqrt()
{
// TODO: Add your control notification handler code here
m_operator=OpSqrt;
perform( );
m_operator=OpNone;
}
void CXYCALCDlg::Onpercent()
{
// TODO: Add your control notification handler code here
if(m_operator==OpMultiply)
{
m_accum=m_accum*m_operand/100.0;
m_operavail=FALSE;
updatedisp( );
}
if(m_operator==OpDivide)
{
m_accum/=m_operand;
m_accum/=100.0;
m_operavail=FALSE;
updatedisp( );
// m_operator=OpDivide;
}
if(m_operator==OpAdd)
{ m_operand=m_operand*m_accum/100.0;
updatedisp( );
m_operator=OpAdd;}
if (m_operator==OpSubtract)
{ m_operand=m_operand*m_accum/100.0;
updatedisp( );
m_operator=OpSubtract;
}
}
void CXYCALCDlg::Ondaoshu()
{
// TODO: Add your control notification handler code here
if((m_operavail)&&(m_operand))
m_operand=1.0/m_operand;
else
m_accum=1.0/m_accum;
updatedisp( );
}
void CXYCALCDlg::Onequal()
{
// TODO: Add your control notification handler code here
perform( );
m_operator = OpNone;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -