1、Visual C+ 6.0或Dev-cpp内容1. 利用MFC的向导创建基于对话框的应用程序,添加按钮、编辑框等控件。2. 实现算术“加、减、乘、除”的运算。3. 选做添加计算三角函数运算、对数运算、指数运算、进制转换等功能。 算法描述步骤1. 利用MFC AppWizard 向导建立程序框架,建立一个基于对话框的程序,项目名为MyCal。2. 利用资源编辑器,建立对话框。添加一个编辑框,设置ID属性。3. 在控件工具栏中选择“Button”,添加一个按钮,鼠标右键单击该编辑框,在弹出快捷菜单中选择“Properties”,设置ID值和Caption属性。4. 依次添加若干编辑框和按钮,分别用
2、于加减乘除操作及相应的操作数据。编辑界面。5. 给编辑框连接变量。在编辑框处点击右键选择“ClassWizard”,在弹出的对话框中选择“Member Variables”选项卡,找到编辑框ID,选择“Add Variable”按钮,添加变量m_dispiay。6. 给按钮连接代码。 调试过程结果将程序代码在Visual C+ 6.0中进行程序调试,更改代码错误后编译通过,并输出调试后的最终结果。输出结果如下: 总 结实验五主要考察了使用Visual C+的MFC开发程序的方法。通过实验五的再学习现作如下总结:1. 通过本次实验,初步掌握了MFC的基本使用操作,学会了掌握添加按钮、编辑框等控件
3、。2. 对MFC的理解无非就是对按钮和编辑框链接相应的函数操作即可。3. 程序中出现了关于Visual C+版本的要求,在编译时提示缺少MFC42D.DLL、MFCO42D.DLL、MSVCRTD.dll等提示。 附录实验五程序代码如下:/ MyCalDlg.cpp : implementation file/#include stdafx.hMyCal.hMyCalDlg.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CAboutDlg dialog used
4、 for App Aboutclass CAboutDlg : public CDialogpublic: 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_VIRTU
5、AL/ Implementationprotected: /AFX_MSG(CAboutDlg) /AFX_MSG DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD) /AFX_DATA_INIT(CAboutDlg) /AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange* pDX) CDialog:DoDataExchange(pDX); /AFX_DATA_MAP(CAboutDlg) /AFX_DATA_MAPBEGIN_MESSAGE_MA
6、P(CAboutDlg, CDialog) /AFX_MSG_MAP(CAboutDlg) / No message handlers /AFX_MSG_MAPEND_MESSAGE_MAP()/ CMyCalDlg dialogCMyCalDlg:CMyCalDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyCalDlg:IDD, pParent) /AFX_DATA_INIT(CMyCalDlg) m_display = _T(); / Note that LoadIcon does not require a subsequent DestroyIcon
7、 in Win32 m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CMyCalDlg: /AFX_DATA_MAP(CMyCalDlg) DDX_Text(pDX, IDC_EDIT1, m_display);BEGIN_MESSAGE_MAP(CMyCalDlg, CDialog) /AFX_MSG_MAP(CMyCalDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON20, On_add) ON_BN_CLICKED(
8、IDC_BUTTON17, On_divide) ON_BN_CLICKED(IDC_BUTTON9, On_equal) ON_BN_CLICKED(IDC_BUTTON1, On_one) ON_BN_CLICKED(IDC_BUTTON2, On_two) ON_BN_CLICKED(IDC_BUTTON5, On_three) ON_BN_CLICKED(IDC_BUTTON11, On_four) ON_BN_CLICKED(IDC_BUTTON3, On_five) ON_BN_CLICKED(IDC_BUTTON6, On_six) ON_BN_CLICKED(IDC_BUTTO
9、N10, On_seven) ON_BN_CLICKED(IDC_BUTTON12, On_eight) ON_BN_CLICKED(IDC_BUTTON4, On_nine) ON_BN_CLICKED(IDC_BUTTON8, On_zero) ON_BN_CLICKED(IDC_BUTTON7, On_plus_minus) ON_BN_CLICKED(IDC_BUTTON19, On_cut) ON_BN_CLICKED(IDC_BUTTON18, On_multiply) ON_BN_CLICKED(IDC_BUTTON16, On_CE)/ CMyCalDlg message ha
10、ndlersBOOL CMyCalDlg:OnInitDialog()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 AppendMenu(MF_SEPARATOR);AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); / Set the icon
11、for this dialog. The framework does this automatically / when the applications 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 return TRUE; / return TRUE unless you set the focus to a controlOnSysComma
12、nd(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 aut
13、omatically done for you by the framework.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
14、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);OnPaint();/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CMyCalDlg:OnQueryDragIcon() r
15、eturn (HCURSOR) m_hIcon;On_add() Add your control notification handler code here op=+; /m_preNum=GetNum(); sscanf(m_display,%lf,&m_preNum); m_display=0 UpdateData(false);On_cut() Add your control notification handler code here -On_multiply() *On_divide() /On_equal() double result=0;m_curNum); switch
16、(op) caseresult=m_preNum+m_curNum;break;result=m_preNum-m_curNum; caseresult=m_preNum*m_curNum;result=m_preNum/m_curNum; m_preNum=result; char s256=0; sprintf(s,result); m_display=s;On_one() m_display+=1On_two() 2On_three() 3On_four() 4On_five() 5On_six() 6On_seven() 7On_eight() 8On_nine() 9On_zero() 0On_plus_minus() ,s);- m_display+=s;On_CE() m_preNum=0; m_curNum=0;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1