1、步骤2:将图示的调用结构用菜单消息实现。(1)每个下层模块用子菜单呈现。(2)底层模块用对话框实现。过程:1、运行VC+6.0开发平台,选择“文件”“新建”“MFC Appwizard(exe)”,工程名称设为“Hotel_MIS”,选择工程存放路径,确定2、选择“单文档”,点击“完成”按钮,进入如图1界面图13、选择“ResourceView”选项卡,依次展开“Hotel_MIS resources”“Menu”文件夹,双击Menu文件夹下的“IDR_MAINFRAME”,出现如图2所示结果图24、添加功能模块,如图3所示图35、在“ResourceView”选项卡,依次展开“Hotel_M
2、IS resources”“Dialog”文件夹,右键点击“Dialog”创建对话框,如图4所示图46、在每个功能模块的属性框将ID改为IDD_ABOUTBOX,编译执行结果如图5所示图5步骤3:总结实验和设计经验,编写实验报告详细代码:/ Hotel_MIS.cpp : Defines the class behaviors for the application./#include stdafx.hHotel_MIS.hMainFrm.hHotel_MISDoc.hHotel_MISView.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FI
3、LEstatic char THIS_FILE = _FILE_;#endif/ CHotel_MISAppBEGIN_MESSAGE_MAP(CHotel_MISApp, CWinApp) /AFX_MSG_MAP(CHotel_MISApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) / NOTE - the ClassWizard will add and remove mapping macros here. / DO NOT EDIT what you see in these blocks of generated code! /AFX_MSG_MA
4、P / Standard file based document commands ON_COMMAND(ID_FILE_NEW, CWinApp:OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp:OnFileOpen) / Standard print setup command ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp:OnFilePrintSetup)END_MESSAGE_MAP()/ CHotel_MISApp constructionCHotel_MISApp:CHotel_MISApp() / TODO:
5、 add construction code here, / Place all significant initialization in InitInstance/ The one and only CHotel_MISApp objectCHotel_MISApp theApp;/ CHotel_MISApp initializationBOOL CHotel_MISApp:InitInstance() AfxEnableControlContainer(); / Standard initialization / If you are not using these features
6、and wish to reduce the size / of your final executable, you should remove from the following / the specific initialization routines you do not need.#ifdef _AFXDLL Enable3dControls(); / Call this when using MFC in a shared DLL#else Enable3dControlsStatic(); / Call this when linking to MFC statically
7、/ Change the registry key under which our settings are stored. You should modify this string to be something appropriate / such as the name of your company or organization. SetRegistryKey(_T(Local AppWizard-Generated Applications); LoadStdProfileSettings(); / Load standard INI file options (includin
8、g MRU) / Register the applications document templates. Document templates / serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CHotel_MISDoc), RUNTIME_CLASS(CMainFrame), / main SDI
9、frame window RUNTIME_CLASS(CHotel_MISView); AddDocTemplate(pDocTemplate); / Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); / Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo) return FALSE; / The one
10、and only window has been initialized, so show and update it. m_pMainWnd-ShowWindow(SW_SHOW);UpdateWindow(); return TRUE;/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogpublic: CAboutDlg();/ Dialog Data /AFX_DATA(CAboutDlg) enum IDD = IDD_ABOUTBOX ; /AFX_DATA / ClassWizard genera
11、ted virtual function overrides /AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV support /AFX_VIRTUAL/ Implementationprotected: /AFX_MSG(CAboutDlg) / No message handlers /AFX_MSG DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD) /AFX_DAT
12、A_INIT(CAboutDlg) /AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange* pDX) CDialog:DoDataExchange(pDX); /AFX_DATA_MAP(CAboutDlg) /AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg, CDialog) /AFX_MSG_MAP(CAboutDlg)/ App command to run the dialogvoid CHotel_MISApp:OnAppAbout() CAboutDlg aboutDlg; aboutDl
13、g.DoModal();/ CHotel_MISApp message handlers/ Hotel_MISView.cpp : implementation of the CHotel_MISView class/ CHotel_MISViewIMPLEMENT_DYNCREATE(CHotel_MISView, CView)BEGIN_MESSAGE_MAP(CHotel_MISView, CView) /AFX_MSG_MAP(CHotel_MISView) / Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView:OnF
14、ilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView: ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView:OnFilePrintPreview)/ CHotel_MISView construction/destructionCHotel_MISView:CHotel_MISView() add construction code hereCHotel_MISView()BOOL CHotel_MISView:PreCreateWindow(CREATESTRUCT& cs) Modify the Window clas
15、s or styles here by modifying / the CREATESTRUCT cs return CView:PreCreateWindow(cs);/ CHotel_MISView drawingvoid CHotel_MISView:OnDraw(CDC* pDC) CHotel_MISDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); add draw code for native data here/ CHotel_MISView printingOnPreparePrinting(CPrintInfo* pInfo) /
16、 default preparation return DoPreparePrinting(pInfo);OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) add extra initialization before printingOnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) add cleanup after printing/ CHotel_MISView diagnosticsAssertValid() const CView:AssertValid();Dump(CDum
17、pContext& dc) constDump(dc);CHotel_MISDoc* CHotel_MISView:GetDocument() / non-debug version is inline ASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CHotel_MISDoc); return (CHotel_MISDoc*)m_pDocument;#endif /_DEBUG/ CHotel_MISView message handlers实验总结:通过这次实验,我对事件驱动的基本架构有所了解,并了解基于事件驱动模式的编程的基本设计方法,对WINDOWS的程序平台上的设计实现方法也有一定掌握,但仍有许多不足之处,比如在编程实现方面仍然很薄弱,我将在今后的学习中加强这方面上的练习。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1