C++ 实验六 简单的MFC应用程序设计C++ 实验六 简单的MFC应用程序设计.doc
文本预览下载声明
.
简单的MFC应用程序设计
一、实验目的
理解Windows编程特点;
了解MFC应用程序的消息映射、数据映射机制;
掌握用AppWizard(exe)创建SDI和MDI应用程序的方法;
掌握使用项目工作区窗口的ClassView页面为类添加成员的方法;
掌握用ClassWizard映射消息的方法。
掌握对话框编辑器的使用方法;
熟悉对话框的编程过程及控件的创建和使用方法;
掌握静态控件、按钮和编辑框控件的使用方法。
二、内容与设计思想
上机实践内容:
设计一个对话框,用于学生成绩的输入,要求能输入学生姓名、学号、性别以及3门课程成绩,单击“求平均”按钮是计算3门课程的平均成绩并显示在上面的静态文本框中。通过单击“测试”菜单下的“成绩录入”子菜单调用该对话框,在该对话框中要用到控件:静态文本、编辑框(单行和多行)、单选框、复选框、组框、按钮等,其运行结果如下:
三、使用环境
操作系统:Windowns XP
C++环境:Visual C++ 6.0
四、核心代码及调试过程
#include ScoreInput.h
#include MainFrm.h
#include ScoreInputDoc.h
#include ScoreInputView.h
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CScoreInputApp, CWinApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
CScoreInputApp::CScoreInputApp()
{
}
CScoreInputApp theApp;
BOOL CScoreInputApp::InitInstance()
{
AfxEnableControlContainer();
#ifdef _AFXDLL
Enable3dControls();
Enable3dControlsStatic();
SetRegistryKey(_T(Local AppWizard-Generated Applications));
LoadStdProfileSettings();
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CScoreInputDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CScoreInputView));
AddDocTemplate(pDocTemplate);
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (!ProcessShellCommand(cmdInfo))
return FALSE;
m_pMainWnd-ShowWindow(SW_SHOW);
m_pMainWnd-UpdateWindow();
return TRUE;
}
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
CButton m_Avg;
float m_avg;
int m_english;
int m_yuwen;
int m_math;
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
afx_msg void OnButton1();
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
m_avg = 0.0f;
m_english = 0;
m_yuwen = 0;
显示全部