MFC程序引导过程(二)

来源:互联网 发布:js apply原理 编辑:程序博客网 时间:2024/06/14 22:45
<pre name="code" class="cpp"><pre name="code" class="cpp">// 333.cpp : Defines the class behaviors for the application.//#include "stdafx.h"#include "333.h"#include "333Dlg.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CMy333AppBEGIN_MESSAGE_MAP(CMy333App, CWinApp)//{{AFX_MSG_MAP(CMy333App)// NOTE - the ClassWizard will add and remove mapping macros here.//    DO NOT EDIT what you see in these blocks of generated code!//}}AFX_MSGON_COMMAND(ID_HELP, CWinApp::OnHelp)END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CMy333App constructionCMy333App::CMy333App(){// TODO: add construction code here,// Place all significant initialization in InitInstance}/////////////////////////////////////////////////////////////////////////////// The one and only CMy333App objectCWinApp?CMy333App theApp;第一步:实例化应用程序类的对象(CWinApp),在当前程序的333.h文件中有:class CMy333App : public CWinApp1.一个MFC程序,有且只有一个从WinApp派生出的类(应用程序类)-》CMy333App?,也只有一个从应用程序对象所实例化的对象表示应用程序本身,theApp;2.在MFC应用程序中,是通过产生一个应用程序对象,用它来唯一表示了应用程序;3.构造应用程序对象时,调用基类CWinApp的构造函数/////////////////////////////////////////////////////////////////////////////// CMy333App initializationBOOL CMy333App::InitInstance()第二步:调用应用程序类中的InitInstance()函数,该函数在基类中定义为虚函数{if (!AfxSocketInit()){AfxMessageBox(IDP_SOCKETS_INIT_FAILED);return FALSE;}AfxEnableControlContainer();// Standard initialization// If you are not using these features 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 _AFXDLLEnable3dControls();// Call this when using MFC in a shared DLL#elseEnable3dControlsStatic();// Call this when linking to MFC statically#endifCMy333Dlg dlg;第三步:定义主对话框类的对象dlg;并且调用对话框类的构造函数CMy333Dlg(CWnd *pParent=Null);注:333Dlg.h的头文件中有class CMy333Dlg : public CDialogm_pMainWnd = &dlg;int nResponse = dlg.DoModal();第四步:调用主对话框对象的DoModal()函数,??||—>a.调用主对话框对象中的OnInitDialog()函数初始化对话框|  OnInitDialog()是CDialog类的一个虚函数,可以由子类重载。|  当CDiaog子类调用DoModal()函数时,就会触发一系列函数调用,|  最终调用OnInitDialog()。可以在VC6中创建一个基于对话框的MFC应用程序,|  在OnInitDialog里面打上断点,当程序运行进入断点是,打开调用堆栈窗口,|  就可以跟踪得到调用OnInitDialog()的函数。||—>b.调用OnPaint()函数,绘制窗口第五步:对话框退出后,返回DoModel()函数状态给nResponseif (nResponse == IDOK){// TODO: Place code here to handle when the dialog is//  dismissed with OK}else if (nResponse == IDCANCEL){// TODO: Place code here to handle when the dialog is//  dismissed with Cancel}// Since the dialog has been closed, return FALSE so that we exit the//  application, rather than start the application's message pump.return FALSE;}


</pre>
0 0
原创粉丝点击