windows循序渐进Chapter_1讲解.ppt

—— Chapter 1 软件开发起步 2009-09-02 1.1 建立MFC应用程序 使用MFC框架生成一个默认的对话框 对话框生成流程(1) 对话框生成流程(2) 对话框生成流程(3) 对话框生成流程(4) 对话框生成流程(5) 对话框生成流程(6) 对话框生成流程(7) 对话框生成流程(8) 对话框生成流程(9) 对话框生成流程(10) 对话框生成流程(11) 对话框生成流程(12) 对话框生成流程(13) 对话框生成流程(14) 对话框生成流程(15) 对话框生成流程(16) 对话框生成流程(17) 1.2 分析框架结构 本节介绍上一节所生成的框架代码 1.2.1 框架代码文件的结构 基于MFC对话框程序的框架代码主要由以下几个部分组成: 1)应用程序类:项目名称为FirstSoftware,对应类名为CFirstSoftwareApp; 2)对话框类: 项目名称为FirstSoftware,对应类名为CFirstSoftwareDlg; 3)资源文件:定义资源ID,一般不用手动修改; 4)预编译文件:可以用来解决头文件包含冲突的问题,定义了一些需要全局性包含的文件。 1.2 分析框架结构 1.2.2 应用程序类 MFC定义了一个应用程序基类CWinApp,所有的基于MFC的应用程序都会继承这个类。 这里,FirstSoftware项目也不例外,此时的应用程序类为CFirstSoftwareApp。 1.2 分析框架结构 1.2.2 应用程序类 此时应用程序类CFirstSoftwareApp定义如下: // CFirstSoftwareApp initialization BOOL CFirstSoftwareApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(InitCtrls); CWinApp::InitInstance(); AfxEnableControlContainer(); //AfxEnableControlContainer()函数是允许应用程序作为控件容器//来使用,也就是说你可以在这个应用程序中使用ocx之类的控//件。对于用MFC向导自动生成的单文档框架程序的//C...APP::InitInstance()函数中自动加了这一句; //如果在程序中使用控件时弹出莫名其妙的错误的时候,看看是//不是没有加这一句。 SetRegistryKey(_T(Local AppWizard-Generated Applications)); //定义对话框对象 CFirstSoftwareDlg dlg; //保存对话框到全局变量 m_pMainWnd = dlg; //显示对话框 INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog isdismissed with Cancel } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog isdismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the //app

文档评论(0)

1亿VIP精品文档

相关文档