MFC计算器主要代码C++文档格式.docx
《MFC计算器主要代码C++文档格式.docx》由会员分享,可在线阅读,更多相关《MFC计算器主要代码C++文档格式.docx(24页珍藏版)》请在冰豆网上搜索。
![MFC计算器主要代码C++文档格式.docx](https://file1.bdocx.com/fileroot1/2022-10/27/2816df63-62a3-4142-945b-845ea0286954/2816df63-62a3-4142-945b-845ea02869541.gif)
CAboutDlg();
//DialogData
enum{IDD=IDD_ABOUTBOX};
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);
//DDX/DDVsupport
//Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg:
:
CAboutDlg():
CDialogEx(CAboutDlg:
IDD)
}
voidCAboutDlg:
DoDataExchange(CDataExchange*pDX)
CDialogEx:
DoDataExchange(pDX);
BEGIN_MESSAGE_MAP(CAboutDlg,CDialogEx)
END_MESSAGE_MAP()
//CCalculator_17483Dlgdialog
CCalculator_17483Dlg:
CCalculator_17483Dlg(CWnd*pParent/*=NULL*/)
:
CDialogEx(CCalculator_17483Dlg:
IDD,pParent)
num1=0;
num2=0;
operation=0;
point=0;
nump_1=0;
nump_2=0;
m_hIcon=AfxGetApp()->
LoadIcon(IDR_MAINFRAME);
voidCCalculator_17483Dlg:
BEGIN_MESSAGE_MAP(CCalculator_17483Dlg,CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1,&
OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2,&
OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON3,&
OnBnClickedButton3)
ON_BN_CLICKED(IDC_BUTTON4,&
OnBnClickedButton4)
ON_BN_CLICKED(IDC_BUTTON5,&
OnBnClickedButton5)
ON_BN_CLICKED(IDC_BUTTON6,&
OnBnClickedButton6)
ON_BN_CLICKED(IDC_BUTTON7,&
OnBnClickedButton7)
ON_BN_CLICKED(IDC_BUTTON8,&
OnBnClickedButton8)
ON_BN_CLICKED(IDC_BUTTON9,&
OnBnClickedButton9)
ON_BN_CLICKED(IDC_BUTTON10,&
OnBnClickedButton10)
ON_BN_CLICKED(IDC_BUTTON11,&
OnBnClickedButton11)
ON_BN_CLICKED(IDC_BUTTON12,&
OnBnClickedButton12)
ON_BN_CLICKED(IDC_BUTTON13,&
OnBnClickedButton13)
ON_BN_CLICKED(IDC_BUTTON14,&
OnBnClickedButton14)
ON_BN_CLICKED(IDC_BUTTON15,&
OnBnClickedButton15)
ON_BN_CLICKED(IDC_BUTTON16,&
OnBnClickedButton16)
ON_BN_CLICKED(IDC_BUTTON17,&
OnBnClickedButton17)
//CCalculator_17483Dlgmessagehandlers
BOOLCCalculator_17483Dlg:
OnInitDialog()
OnInitDialog();
//Add"
About..."
menuitemtosystemmenu.
//IDM_ABOUTBOXmustbeinthesystemcommandrange.
ASSERT((IDM_ABOUTBOX&
0xFFF0)==IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX<
0xF000);
CMenu*pSysMenu=GetSystemMenu(FALSE);
if(pSysMenu!
=NULL)
{
BOOLbNameValid;
CStringstrAboutMenu;
bNameValid=strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if(!
strAboutMenu.IsEmpty())
{
pSysMenu->
AppendMenu(MF_SEPARATOR);
AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);
}
}
//Settheiconforthisdialog.Theframeworkdoesthisautomatically
//whentheapplication'
smainwindowisnotadialog
SetIcon(m_hIcon,TRUE);
//Setbigicon
SetIcon(m_hIcon,FALSE);
//Setsmallicon
//TODO:
Addextrainitializationhere
returnTRUE;
//returnTRUEunlessyousetthefocustoacontrol
OnSysCommand(UINTnID,LPARAMlParam)
if((nID&
0xFFF0)==IDM_ABOUTBOX)
CAboutDlgdlgAbout;
dlgAbout.DoModal();
else
CDialogEx:
OnSysCommand(nID,lParam);
//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow
//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,
//thisisautomaticallydoneforyoubytheframework.
OnPaint()
if(IsIconic())
CPaintDCdc(this);
//devicecontextforpainting
SendMessage(WM_ICONERASEBKGND,reinterpret_cast<
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);
OnPaint();
//Thesystemcallsthisfunctiontoobtainthecursortodisplaywhiletheuserdrags
//theminimizedwindow.
HCURSORCCalculator_17483Dlg:
OnQueryDragIcon()
returnstatic_cast<
HCURSOR>
(m_hIcon);
OnBnClickedButton13()//0
if(operation==0){
num1=num1*10+0;
string_num1.Format(_T("
%d"
),num1);
SetDlgItemTextW(IDC_EDIT1,string_num1);
else{
num2=num2*10+0;
string_num2.Format(_T("
),num2);
SetDlgItemTextW(IDC_EDIT2,string_num2);
Addyourcontrolnotificationhandler