正在加载图片...
第3章 Windows编程与MFC AfxwinTerm( return nReturncode 应用程序执行时, Windows自动调用应用程序框架内部的 Winmain函数。从上面的代码清单中可 见, Winmail函数会查找该应用程序的一个全局构造对象,这个对象是由 CWinAp派生类构造的,并 且只有一个。它是一个全局对象,因此在程序启动时,它就已经被构造好了。 随后, Winmain将调用这个对象的 InitApplication(和 InitInstance成员函数,完成应用程序实例 的初始化工作。随后, Winmain调用Run()成员函数,运行应用程序的消息循环。在程序结束时, Winmain调用 AfxWinTerm(函数,做一些清理工作。 2.4.2应用程序对象 每个应用程序必须从 CWinApp派生出自己的应用程序类,并定义一个全局的对象。该应用程序类 包含了 Windows下应用程序的初始化、运行和结束过程。基于框架建立的应用程序必须有一个(且只 能有一个)从 CWinApp派生的类的对象 在工程“ SDIDemo”的 CSDIDemoApp类的源文件中,可以发现框架自动生成了应用程序对象,如下 / The one and only csDI DemoApp object CSDIDemoApp theApp; 24.3 nitInstanceo函数 CWinApp类中的 IInitInstanceo函数用于初始化实例。每次启动应用程序的一个实例时, WinMain 函数都要调用 InitInstanceo函数 在工程“ SDIDemo”的 CSDIDemoApp类中,自动对 InitInstance(函数进行了重载,代码如下: moPp:: In AfxEnablecontrolContainer() #ifdef AFXDLL Enable3dcontrols()i // call this when using MEc in a shared DLL Enable3dcontrolsstatic( / call this when linking to MEc statically / Change the registry key under which our settings are stored / TODO: 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 (including MRU) / Register the application's document templates. Document templates // csingleDocTemplate* pDocTemplate new csingleDoc IDR MAINFRAME RUNTIME CLASS (CSDIDemo Doc RUNTIME CLASS (CMainFrame / main sDI frame window 励志照亮人生编程改变命AfxWinTerm(); return nReturnCode; } 应用程序执行时,Windows自动调用应用程序框架内部的WinMain函数。从上面的代码清单中可 见,WinMain函数会查找该应用程序的一个全局构造对象,这个对象是由CWinApp派生类构造的,并 且只有一个。它是一个全局对象,因此在程序启动时,它就已经被构造好了。 随后,WinMain将调用这个对象的InitApplication()和InitInstance()成员函数,完成应用程序实例 的初始化工作。随后,WinMain调用Run()成员函数,运行应用程序的消息循环。在程序结束时, WinMain调用AfxWinTerm()函数,做一些清理工作。 2.4.2 应用程序对象 每个应用程序必须从CWinApp派生出自己的应用程序类,并定义一个全局的对象。该应用程序类 包含了Windows下应用程序的初始化、运行和结束过程。基于框架建立的应用程序必须有一个(且只 能有一个)从CWinApp派生的类的对象。 在工程“SDIDemo”的CSDIDemoApp类的源文件中,可以发现框架自动生成了应用程序对象,如下: // The one and only CSDIDemoApp object CSDIDemoApp theApp; 2.4.3 InitInstance()函数 CWinApp类中的InitInstance()函数用于初始化实例。每次启动应用程序的一个实例时,WinMain 函数都要调用InitInstance()函数。 在工程“SDIDemo”的CSDIDemoApp类中,自动对InitInstance()函数进行了重载,代码如下: BOOL CSDIDemoApp::InitInstance() { AfxEnableControlContainer(); #ifdef_AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // TODO: 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 (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CSDIDemoDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window 41 励志照亮人生 编程改变命运 第 3 章 Windows编程与MFC基础
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有