C++MFC 计算其开发.docx
- 文档编号:23377519
- 上传时间:2023-05-16
- 格式:DOCX
- 页数:24
- 大小:25.23KB
C++MFC 计算其开发.docx
《C++MFC 计算其开发.docx》由会员分享,可在线阅读,更多相关《C++MFC 计算其开发.docx(24页珍藏版)》请在冰豆网上搜索。
C++MFC计算其开发
//CalculatorDlg.cpp:
implementationfile
//
#include"stdafx.h"
#include"Calculator.h"
#include"CalculatorDlg.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
#include
#include
/////////////////////////////////////////////////////////////////////////////
//CAboutDlgdialogusedforAppAbout
classCAboutDlg:
publicCDialog
{
public:
CAboutDlg();
//DialogData
//{{AFX_DATA(CAboutDlg)
enum{IDD=IDD_ABOUTBOX};
//}}AFX_DATA
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport
//}}AFX_VIRTUAL
//Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg:
:
CAboutDlg():
CDialog(CAboutDlg:
:
IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
voidCAboutDlg:
:
DoDataExchange(CDataExchange*pDX)
{
CDialog:
:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//Nomessagehandlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CCalculatorDlgdialog
CCalculatorDlg:
:
CCalculatorDlg(CWnd*pParent/*=NULL*/)
:
CDialog(CCalculatorDlg:
:
IDD,pParent)
{
//{{AFX_DATA_INIT(CCalculatorDlg)
//NOTE:
theClassWizardwilladdmemberinitializationhere
//}}AFX_DATA_INIT
//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32
m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
voidCCalculatorDlg:
:
DoDataExchange(CDataExchange*pDX)
{
CDialog:
:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCalculatorDlg)
DDX_Control(pDX,IDC_EDIT1,m_w);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCalculatorDlg,CDialog)
//{{AFX_MSG_MAP(CCalculatorDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
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_BUTTON10,OnButton10)
ON_BN_CLICKED(IDC_BUTTON11,OnButton11)
ON_BN_CLICKED(IDC_BUTTON12,OnButton12)
ON_BN_CLICKED(IDC_BUTTON13,OnButton13)
ON_BN_CLICKED(IDC_BUTTON14,OnButton14)
ON_BN_CLICKED(IDC_BUTTON15,OnButton15)
ON_BN_CLICKED(IDC_BUTTON16,OnButton16)
ON_BN_CLICKED(IDC_BUTTON17,OnButton17)
ON_BN_CLICKED(IDC_BUTTON18,OnButton18)
ON_BN_CLICKED(IDC_BUTTON19,OnButton19)
ON_BN_CLICKED(IDC_BUTTON20,OnButton20)
ON_BN_CLICKED(IDC_BUTTON21,OnButton21)
ON_BN_CLICKED(IDC_BUTTON22,OnButton22)
ON_BN_CLICKED(IDC_BUTTON23,OnButton23)
ON_BN_CLICKED(IDC_BUTTON24,OnButton24)
ON_BN_CLICKED(IDC_BUTTON25,OnButton25)
ON_BN_CLICKED(IDC_BUTTON26,OnButton26)
ON_BN_CLICKED(IDC_BUTTON27,OnButton27)
ON_BN_CLICKED(IDC_BUTTON28,OnButton28)
ON_BN_CLICKED(IDC_BUTTON29,OnButton29)
ON_BN_CLICKED(IDC_BUTTON30,OnButton30)
ON_BN_CLICKED(IDC_BUTTON31,OnButton31)
ON_BN_CLICKED(IDC_BUTTON34,OnButton34)
ON_BN_CLICKED(IDC_BUTTON33,OnButton33)
ON_BN_CLICKED(IDC_BUTTON32,OnButton32)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CCalculatorDlgmessagehandlers
BOOLCCalculatorDlg:
:
OnInitDialog()
{
CDialog:
:
OnInitDialog();
//Add"About..."menuitemtosystemmenu.
//IDM_ABOUTBOXmustbeinthesystemcommandrange.
ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX<0xF000);
CMenu*pSysMenu=GetSystemMenu(FALSE);
if(pSysMenu!
=NULL)
{
CStringstrAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if(!
strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);
}
}
//Settheiconforthisdialog.Theframeworkdoesthisautomatically
//whentheapplication'smainwindowisnotadialog
SetIcon(m_hIcon,TRUE);//Setbigicon
SetIcon(m_hIcon,FALSE);//Setsmallicon
//TODO:
Addextrainitializationhere
b=true;
returnTRUE;//returnTRUEunlessyousetthefocustoacontrol
}
voidCCalculatorDlg:
:
OnSysCommand(UINTnID,LPARAMlParam)
{
if((nID&0xFFF0)==IDM_ABOUTBOX)
{
CAboutDlgdlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog:
:
OnSysCommand(nID,lParam);
}
}
//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow
//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,
//thisisautomaticallydoneforyoubytheframework.
voidCCalculatorDlg:
:
OnPaint()
{
if(IsIconic())
{
CPaintDCdc(this);//devicecontextforpainting
SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);
//Centericoninclientrectangle
intcxIcon=GetSystemMetrics(SM_CXICON);
intcyIcon=GetSystemMetrics(SM_CYICON);
CRectrect;
GetClientRect(&rect);
intx=(rect.Width()-cxIcon+1)/2;
inty=(rect.Height()-cyIcon+1)/2;
//Drawtheicon
dc.DrawIcon(x,y,m_hIcon);
}
else
{
CDialog:
:
OnPaint();
}
}
//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags
//theminimizedwindow.
HCURSORCCalculatorDlg:
:
OnQueryDragIcon()
{
return(HCURSOR)m_hIcon;
}
voidCCalculatorDlg:
:
OnButton1()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(atof(s)==0&&b==true)
{
s="";
s+="1";
}
else
s+="1";
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton2()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(atof(s)==0&&b==true)
{
s="";
s+="2";
}
else
s+="2";
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton3()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(atof(s)==0&&b==true)
{
s="";
s+="3";
}
else
s+="3";
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton4()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(atof(s)==0&&b==true)
{
s="";
s+="4";
}
else
s+="4";
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton5()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(atof(s)==0&&b==true)
{
s="";
s+="5";
}
else
s+="5";
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton6()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(atof(s)==0&&b==true)
{
s="";
s+="6";
}
else
s+="6";
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton7()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(atof(s)==0&&b==true)
{
s="";
s+="7";
}
else
s+="7";
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton8()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(atof(s)==0&&b==true)
{
s="";
s+="8";
}
else
s+="8";
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton9()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(atof(s)==0&&b==true)
{
s="";
s+="9";
}
else
s+="9";
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton10()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(atof(s)==0&&b==true)
s="0";
else
s+="0";
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton11()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
x=-x;
s.Format("%lg",x);
m_w.SetWindowText(s);
}
voidCCalculatorDlg:
:
OnButton12()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(s!
=""&&b==true)
{
s+=".";
m_w.SetWindowText(s);
b=false;
}
elseif(s==""&&b==true)
{
s+="0.";
m_w.SetWindowText(s);
b=false;
}
}
voidCCalculatorDlg:
:
OnButton13()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
a=1;
m_w.GetWindowText(s);
x=atof(s);
s="";
b=true;
}
voidCCalculatorDlg:
:
OnButton14()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
a=2;
m_w.GetWindowText(s);
x=atof(s);
s="";
b=true;
}
voidCCalculatorDlg:
:
OnButton15()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
a=3;
m_w.GetWindowText(s);
x=atof(s);
s="";
b=true;
}
voidCCalculatorDlg:
:
OnButton16()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
a=4;
m_w.GetWindowText(s);
x=atof(s);
s="";
b=true;
}
voidCCalculatorDlg:
:
OnButton17()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
m_w.GetWindowText(s);
y=atof(s);
switch(a)
{
case1:
s.Format("%lg",x+y);break;
case2:
s.Format("%lg",x-y);break;
case3:
s.Format("%lg",x*y);break;
case4:
if(y!
=0)
s.Format("%lg",x/y);
else
s.Format("除数不能为0!
");
break;
case5:
if(x>=0)s.Format("%lg",pow(x,y));
elses.Format("函数输入无效!
");
break;
case6:
if(x>0)s.Format("%lg",log(x)/log(y));
elses.Format("函数输入无效!
");b=true;
}
m_w.SetWindowText(s);
s="";
b=true;
}
voidCCalculatorDlg:
:
OnButton18()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
s="0";
m_w.SetWindowText(s);
b=true;
}
voidCCalculatorDlg:
:
OnButton19()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(s.GetLength()==1)
s="";
else
s=s.Left(s.GetLength()-1);
m_w.SetWindowText(s);
//for(inti=s.GetLength();i>=0;i--)
//{if(s[i]=='.')b=false;
//elseb=true;}
}
voidCCalculatorDlg:
:
OnButton20()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
m_w.GetWindowText(s);
x=atof(s);
if(x!
=0)
s.Format("%lg",1/x);
else
s.Format("除数不能为0!
");
m_w.SetWindowText(s);
s="";
b=true;
}
voidCCalculatorDlg:
:
OnButton21()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
doublei,m=1;
m_w.GetWindowText(s);
x=at
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+MFC 计算其开发 MFC 计算 开发